From patchwork Tue Mar 28 08:25:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 75892 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2054759vqo; Tue, 28 Mar 2023 01:26:12 -0700 (PDT) X-Google-Smtp-Source: AKy350YQ+UgqGI2qyvGWpuKqXi8RSt8IWy+Hpa/TpowJvEykmbd8TcphHZ/iM8xA+IqFD5ZR0ooL X-Received: by 2002:a17:906:3f89:b0:877:a9d2:e5e9 with SMTP id b9-20020a1709063f8900b00877a9d2e5e9mr16294997ejj.42.1679991972025; Tue, 28 Mar 2023 01:26:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679991972; cv=none; d=google.com; s=arc-20160816; b=inLWYRVCJefbdK9T5WQXp82vyHL/ULomVSVoZsZcommebBVrJbct/lcE2pNvhJ8FBI lzYlCJvd50WCimOYOQMgRsou7zTWqvod/J50azlgMjtf7otgSVaiLTuJJLKsojDIqX6H XUpAkYJjmURDTCV+J+kAIpfOEVwxgJ1CD7jbGlQFWH+i9qVH8Wh/uYfMm7YBWTzb4q+W PKbLufemHVwLtlhMrNDaAqxu45k75FS9+2xrX66uwOodK4/3C8KEBd5pe9Q6r//RJ1un +4UoCQaQcKlS3Z4glPHhikfMzZc9i8+3WdUHwZHDJAChRnbbTnCy5A4V1BmzHTGnKu0A PyBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=gRzMkpUIF233bAPjwXHmkBGt1ndNU7rQshgpxVvD420=; b=qI5pcSt4mdWm3+tdz6BzMAV/KHU+o2arj68W+jJ78b1aNnDMcEMx/32P/Doo4qshaD QNFLnBKBWUzkX6hnGGqVHyJLKdwBLM8ia7pVG+b8/7++L5zy034Q2eR7mxingDN1+cwN MdKiql/IXHc7+tvqbrUTTpZ0B0AAejbNRpyoYI/aoeAbTtwPRPUDMoxNy2UcSLy9Yd0K JI9MDGGZHtZ1LWuXDmUIU/sQhdZ3t4XUo2OHtb7U+H1OOwpbzlK8ShPJjawYkvDwMxE3 kUIAh757NosmkkklZ8ve72avU30UEtWHFtsgG2Z7oXLqDCP8nQvle/c9iGNmZPxQvbXF lvrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=fUlRNUxR; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id f15-20020a05640214cf00b00501df17fe9fsi11159735edx.78.2023.03.28.01.26.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 01:26:12 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=fUlRNUxR; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E77EB3858C54 for ; Tue, 28 Mar 2023 08:26:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E77EB3858C54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679991970; bh=gRzMkpUIF233bAPjwXHmkBGt1ndNU7rQshgpxVvD420=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=fUlRNUxRiUSzqxDTwAohyi8R8nivq0kXxKb2p2Q9N69Si7spI1zxBHt6rUgwNbgAU fGlYnJV79ptJSgwn9fUAixzStnfcLlIJaFXB+/6Y6MAKhVEfgFEunSz7vHFRrqzaTa hn1Sg6KCf5RWEjY0T8cBInVOwLnh1iw001g1mius= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id DB8563858D39 for ; Tue, 28 Mar 2023 08:25:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DB8563858D39 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-186-aJwOOzpVNLKR1nvu5B_xWA-1; Tue, 28 Mar 2023 04:25:22 -0400 X-MC-Unique: aJwOOzpVNLKR1nvu5B_xWA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D57CF385F36F; Tue, 28 Mar 2023 08:25:21 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 91E944020C82; Tue, 28 Mar 2023 08:25:21 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 32S8PJfk1442108 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 28 Mar 2023 10:25:19 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 32S8PIRb1442107; Tue, 28 Mar 2023 10:25:18 +0200 Date: Tue, 28 Mar 2023 10:25:18 +0200 To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] match.pd: Fix up sqrt (sqrt (x)) simplification [PR109301] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761599262178549413?= X-GMAIL-MSGID: =?utf-8?q?1761599262178549413?= Hi! The following testcase ICEs since the sincos and vect pass order has been swapped. It is not valid to replace vector sqrt (sqrt (x)) with pow (x, 0.25) because build_real on vector type is invalid (could be handled by using build_uniform_cst and adjusting type passed to build_real) but more importantly because nothing checks if we can actually do vector pow. While we have pow_optab, apparently no target defines it, so it doesn't seem to be worth bothering with for now and the patch just punts on non-scalar sqrts. I think the other simplifications next to it are fine, as they mostly use CBRT which doesn't even have internal function (so is a builtin only and therefore always scalar), or have already pow in the IL (which doesn't have optab and shouldn't be thus vector either). It is true that with we do vectorize some calls to pow or cbrt (but don't handle others strangely), but those aren't using internal functions but simd clones and so match.pd doesn't know anything about those (at least for now). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-03-28 Jakub Jelinek PR tree-optimization/109301 * match.pd (sqrt (sqrt (x)) -> pow (x, 0.25)): Only simplify for scalar floating point types. * gcc.dg/pr109301.c: New test. Jakub --- gcc/match.pd.jj 2023-03-27 10:25:40.171676370 +0200 +++ gcc/match.pd 2023-03-27 21:03:38.816171522 +0200 @@ -6820,7 +6820,8 @@ (define_operator_list SYNC_FETCH_AND_AND /* sqrt(sqrt(x)) -> pow(x,1/4). */ (simplify (sqrts (sqrts @0)) - (pows @0 { build_real (type, dconst_quarter ()); })) + (if (SCALAR_FLOAT_TYPE_P (type)) + (pows @0 { build_real (type, dconst_quarter ()); }))) /* sqrt(cbrt(x)) -> pow(x,1/6). */ (simplify (sqrts (cbrts @0)) --- gcc/testsuite/gcc.dg/pr109301.c.jj 2023-03-27 21:06:22.635806234 +0200 +++ gcc/testsuite/gcc.dg/pr109301.c 2023-03-27 21:06:05.413054906 +0200 @@ -0,0 +1,13 @@ +/* PR tree-optimization/109301 */ +/* { dg-do compile } */ +/* { dg-options "-O3 -ffast-math" } */ + +double x[256]; + +void +foo (void) +{ + for (int i = 0; i < 256; ++i) + for (int j = 0; j < 8; ++j) + x[i] = __builtin_pow (x[i], 0.5); +}