public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-optimization: [PR103245] Improve detection of abs pattern using multiplication
@ 2021-11-16  2:53 apinski
  2021-11-16  3:02 ` Jeff Law
  0 siblings, 1 reply; 2+ messages in thread
From: apinski @ 2021-11-16  2:53 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andrew Pinski

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

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;
+}
-- 
2.17.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] tree-optimization: [PR103245] Improve detection of abs pattern using multiplication
  2021-11-16  2:53 [PATCH] tree-optimization: [PR103245] Improve detection of abs pattern using multiplication apinski
@ 2021-11-16  3:02 ` Jeff Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2021-11-16  3:02 UTC (permalink / raw)
  To: apinski, gcc-patches



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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-11-16  3:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-16  2:53 [PATCH] tree-optimization: [PR103245] Improve detection of abs pattern using multiplication apinski
2021-11-16  3:02 ` Jeff Law

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).