diff mbox series

tree-optimization: [PR103245] Improve detection of abs pattern using multiplication

Message ID 1637031224-15815-1-git-send-email-apinski@marvell.com
State New
Headers show
Series tree-optimization: [PR103245] Improve detection of abs pattern using multiplication | expand

Commit Message

Li, Pan2 via Gcc-patches Nov. 16, 2021, 2:53 a.m. UTC
From: Andrew Pinski <apinski@marvell.com>

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.
---
 gcc/match.pd                               | 22 +++++++++----------
 gcc/testsuite/gcc.dg/tree-ssa/pr103245-1.c | 25 ++++++++++++++++++++++
 2 files changed, 36 insertions(+), 11 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr103245-1.c

Comments

Jeff Law Nov. 16, 2021, 3:02 a.m. UTC | #1
On 11/15/2021 7:53 PM, apinski--- via Gcc-patches wrote:
> From: Andrew Pinski <apinski@marvell.com>
>
> 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.
OK
jeff
diff mbox series

Patch

diff --git a/gcc/match.pd b/gcc/match.pd
index 3b9d13aa24c..dc3d5054583 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -1488,21 +1488,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;
+}