public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-5291] tree-optimization: [PR103245] Improve detection of abs pattern using multiplication
@ 2021-11-16  3:32 Andrew Pinski
  0 siblings, 0 replies; only message in thread
From: Andrew Pinski @ 2021-11-16  3:32 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:3200de91bc70bfd6d4b7b40e769bc82756b9b555

commit r12-5291-g3200de91bc70bfd6d4b7b40e769bc82756b9b555
Author: Andrew Pinski <apinski@marvell.com>
Date:   Mon Nov 15 22:55:09 2021 +0000

    tree-optimization: [PR103245] Improve detection of abs pattern using multiplication
    
    So while working on PR 103228 (and a few others), I noticed the testcase for PR 94785
    was failing. The problem is that the nop_convert moved from being inside the IOR to be
    outside of it. I also noticed the patch for PR 103228 was not needed to reproduce the
    issue either.
    This patch combines the two patterns together for the abs match when using multiplication
    and adds a few places where nop_convert are optional.
    
    OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
    
            PR tree-optimization/103245
    
    gcc/ChangeLog:
    
            * match.pd: Combine the abs pattern matching using multiplication.
            Adding optional nop_convert too.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.dg/tree-ssa/pr103245-1.c: New test.

Diff:
---
 gcc/match.pd                               | 22 +++++++++++-----------
 gcc/testsuite/gcc.dg/tree-ssa/pr103245-1.c | 25 +++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 11 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index a319aefa808..758322da217 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -1478,21 +1478,21 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (absu tree_expr_nonnegative_p@0)
  (convert @0))
 
-/* Simplify (-(X < 0) | 1) * X into abs (X).  */
+/* Simplify (-(X < 0) | 1) * X into abs (X) or absu(X).  */
 (simplify
- (mult:c (bit_ior (negate (convert? (lt @0 integer_zerop))) integer_onep) @0)
- (if (INTEGRAL_TYPE_P (type) && !TYPE_UNSIGNED (type))
-  (abs @0)))
-
-/* Similarly (-(X < 0) | 1U) * X into absu (X).  */
-(simplify
- (mult:c (bit_ior (nop_convert (negate (convert? (lt @0 integer_zerop))))
-		  integer_onep) (nop_convert @0))
+ (mult:c (nop_convert1?
+	  (bit_ior (nop_convert2? (negate (convert? (lt @0 integer_zerop))))
+		    integer_onep))
+	 (nop_convert3? @0))
  (if (INTEGRAL_TYPE_P (type)
-      && TYPE_UNSIGNED (type)
       && INTEGRAL_TYPE_P (TREE_TYPE (@0))
       && !TYPE_UNSIGNED (TREE_TYPE (@0)))
-  (absu @0)))
+  (if (TYPE_UNSIGNED (type))
+   (absu @0)
+   (abs @0)
+  )
+ )
+)
 
 /* A few cases of fold-const.c negate_expr_p predicate.  */
 (match negate_expr_p
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr103245-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr103245-1.c
new file mode 100644
index 00000000000..68ddeadb799
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr103245-1.c
@@ -0,0 +1,25 @@
+/* PR tree-optimization/103245 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* { dg-final { scan-tree-dump-times " = ABSU_EXPR <v_\[0-9]*\\\(D\\\)>;" 1 "optimized" } } */
+
+unsigned
+f1 (int v)
+{
+  unsigned int d_6;
+  int b_5;
+  int a_4;
+  _Bool _1;
+  unsigned int v1_2;
+  unsigned int _7;
+  int _9;
+
+  _1 = v < 0;
+  a_4 = (int) _1;
+  b_5 = -a_4;
+  _9 = b_5 | 1;
+  d_6 = (unsigned int) _9;
+  v1_2 = (unsigned int) v;
+  _7 = v1_2 * d_6;
+  return _7;
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-11-16  3:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-16  3:32 [gcc r12-5291] tree-optimization: [PR103245] Improve detection of abs pattern using multiplication Andrew Pinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).