From patchwork Tue May 9 16:01:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 98948 Delivered-To: patch@linaro.org Received: by 10.182.142.97 with SMTP id rv1csp1992959obb; Tue, 9 May 2017 09:01:39 -0700 (PDT) X-Received: by 10.99.67.69 with SMTP id q66mr966029pga.156.1494345699720; Tue, 09 May 2017 09:01:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1494345699; cv=none; d=google.com; s=arc-20160816; b=W5o+j73O4k0EndUMEejfLh7BWlha0Trg76UKZ3s8bbyYbQzPezkntkiEN+7AMSK6o3 tMB61sVZlhkWnk0TyZiPq+ehUtWQnMDXGl6/orLtDISVChsz8zDVeFNvARtajlB4jys2 DsrbINMA6kUgzMbSNttCoeq5oLh7QiiPb3uiGudHl9IiCJ+3OKXII5Seq+EsLSbU0N0e w29LfwFClfdVFeFkWp10CUCxjZNuYdx1meQxerjF8QbL4LECfglf48cX2rYGuy26u5J1 2cNjhkxnC6N5/sweIjq0EOIquGeXrow59ZvmOhNlheVoRhJRG/D3Ah1P6b/L90GFixjf e4ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:subject:message-id:date:from:mime-version:delivered-to:sender :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=Gkmsh2Ztb7zXYRwPyZ0MFqHN55MC89jQzwffaTnGCm8=; b=b25JaHj5ifk6XcjD03u2IsmebSbKGeHZxrHlWA5mVJ+Gw6dwYVNjpDBvKvfbmcJduV 7RLasUafnJpJqCmIPr5qEfzBeKpu63SvNGslZblSujoneIU9BDdfM1SE01RZfuDj422q XtkJRcK5W4F15jRPtJMY+g90+LUGHBHnlvtNRJ90/Hu1rhzzWLZvJasDDw52KaW/htO2 k2/wLYBwqsNxpJfUJLy1KqJkwnVyaftA16t/CFhmcnlOhMqv3n2Q93MAEZ7J/iOlWQpU WjMJ+G2OULfXkfNmPyKofnGyfGlJ9o25+6iqvAjUGmzZ44TzAQuDGlQe8u8iv7SbLog/ hXHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-453172-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-453172-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id d72si305361pfb.202.2017.05.09.09.01.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 May 2017 09:01:39 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-453172-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-453172-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-453172-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=vlUSlfeXktfCu2YkKy1XTdFJwpCm32315ljqc18OXbQy/M r0r3hY2E3f0EXGScwIqK7+DKe7Kr7J4HPSCiLOXXJXxdabbledDJfsTvlrNdNyj/ EKh1ZtK7BSvaIS5m9Olgk27GJOxTZBDXPtwCTOXNPaO5dJXKhTexk+WRb0/Ls= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=18RYiS6DnE+C+LLl2sGrDX7Uvb8=; b=wBkhdewbDpna5GhUXanM 6q4FkqdN7CTcMoTiidPoD+Pr294ssBC8aj23e8FcDC/bsHCZ17ySN2OInmuTqEq/ Zde/EBcKh+uVlYS/D/OlNIfYH2PopOeHbfrxPrY6cEuR/Bx/eSZQpATbl7XyO/hB 1hk2rMG7IGcGaUc/3s3KM2M= Received: (qmail 12182 invoked by alias); 9 May 2017 16:01:22 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 12169 invoked by uid 89); 9 May 2017 16:01:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=rint X-HELO: mail-it0-f52.google.com Received: from mail-it0-f52.google.com (HELO mail-it0-f52.google.com) (209.85.214.52) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 09 May 2017 16:01:20 +0000 Received: by mail-it0-f52.google.com with SMTP id g126so4408637ith.0 for ; Tue, 09 May 2017 09:01:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=uzoio5BbLiNFqaAWBV5kDWK4r1OnrAcnmVGdCW4nK8A=; b=f9CNEPsmEDiVD1D0GNsb4kdOrl+8mxjkqxtLgT8bmsBp/YonaqjicBqfRadXRclVIw DG2jezWhx8/CvgpVM12hotMq+3EAyw/0UF2miTAtVhLQCIuENy8QjRbsrZ9lv+xISNKP b1eozTy/u0lDCcZ8yre4wWeC0jKLr3T0Qnz2RWYhU+9I5ojRQ0OvC9TDGFrOij00n6zv lOcuYgP92vIxr8MBvG1D9efrNkfq/13h/pQYYGf2wPzq/CKdYDCGCEsD1Btcio2ZwIAb LgdXmXLw2uJ3kUV6Eloku6V76kdhmUKP+LhPsep5FJ81ScOEghyjpe/D0aPX94tLlyBN imcg== X-Gm-Message-State: AODbwcC+yXbFiqwT5P2ErTYKdpfsbQkYGJOZ/YzdGoUwxpPhEeYAvbhp 5zPMET9CuRfI9gDVW2W/CgJfT+nR79sAeuI= X-Received: by 10.36.108.147 with SMTP id w141mr993429itb.57.1494345681040; Tue, 09 May 2017 09:01:21 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.25.5 with HTTP; Tue, 9 May 2017 09:01:20 -0700 (PDT) From: Prathamesh Kulkarni Date: Tue, 9 May 2017 21:31:20 +0530 Message-ID: Subject: PR77644 To: gcc Patches , Richard Biener X-IsSubscribed: yes Hi, The attached patch adds the following pattern to match.pd sqrt(x) cmp sqrt(y) -> x cmp y. and is enabled with -funsafe-math-optimization and -fno-math-errno. Bootstrapped+tested on x86_64-unknown-linux-gnu. Cross-tested on arm*-*-*, aarch64*-*-*. OK for trunk ? Thanks, Prathamesh 2017-05-09 Prathamesh Kulkarni PR tree-optimization/77644 * match.pd (sqrt(x) cmp sqrt(y) -> x cmp y): New pattern. testsuite/ * gcc.dg/tree-ssa/pr77644.c: New test-case. diff --git a/gcc/match.pd b/gcc/match.pd index e3d98baa12f..9929f5a1c16 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2633,7 +2633,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (GENERIC) (truth_andif (ge @0 { build_real (TREE_TYPE (@0), dconst0); }) - (cmp @0 { build_real (TREE_TYPE (@0), c2); })))))))))))) + (cmp @0 { build_real (TREE_TYPE (@0), c2); }))))))))) + + /* PR77644: Transform sqrt(x) cmp sqrt(y) -> x cmp y. */ + (simplify + (cmp (sq @0) (sq @1)) + (if (! HONOR_NANS (type)) + (cmp @0 @1)))))) /* Fold A /[ex] B CMP C to A CMP B * C. */ (for cmp (eq ne) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr77644.c b/gcc/testsuite/gcc.dg/tree-ssa/pr77644.c new file mode 100644 index 00000000000..30da66374e6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr77644.c @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target c99_runtime } */ +/* { dg-options "-O2 -fdump-tree-optimized -funsafe-math-optimizations -fno-math-errno" } */ + +#define FOO(type, cmp, suffix, no) \ +int f_##no(type x, type y) \ +{ \ + type gen_##no(); \ + type xs = __builtin_sqrt##suffix((gen_##no())); \ + type xy = __builtin_sqrt##suffix((gen_##no())); \ + return (xs cmp xy); \ +} + +#define GEN_FOO(type, suffix) \ +FOO(type, <, suffix, suffix##1) \ +FOO(type, <=, suffix, suffix##2) \ +FOO(type, >, suffix, suffix##3) \ +FOO(type, >=, suffix, suffix##4) \ +FOO(type, ==, suffix, suffix##5) \ +FOO(type, !=, suffix, suffix##6) + +GEN_FOO(float, f) +GEN_FOO(double, ) +GEN_FOO(long double, l) + +/* { dg-final { scan-tree-dump-not "__builtin_sqrtf" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "__builtin_sqrt" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "__builtin_sqrtl" "optimized" } } */