Add pattern: abs (abs (x)) -> abs (x)

* match.pd: Add new pattern.

[gcc/testsuite/gcc.dg/tree-ssa]
* match.c: New test-case.

Thanks,
Prathamesh
Index: gcc/match.pd
===================================================================
--- gcc/match.pd	(revision 213814)
+++ gcc/match.pd	(working copy)
@@ -101,6 +101,12 @@ along with GCC; see the file COPYING3.
   (fma INTEGER_CST_P@0 INTEGER_CST_P@1 @3)
   (plus (mult @0 @1) @3))
 
+/* abs (abs (x)) -> abs (x) */
+(simplify
+  (abs (abs @0))
+  (abs @0))
+
+
 #include "match-plusminus.pd"
 #include "match-bitwise.pd"
 #include "match-rotate.pd"
Index: gcc/testsuite/gcc.dg/tree-ssa/match.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/match.c	(revision 0)
+++ gcc/testsuite/gcc.dg/tree-ssa/match.c	(working copy)
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-forwprop1-details" }  */
+
+int abs(int);
+
+int match_1 (int x)
+{
+  int t1 = abs (x);
+  int match_1_val = abs (t1);
+  return match_1_val;
+}  
+/* { dg-final { scan-tree-dump "gimple_simplified to match_1_val_\\d\+ = ABS_EXPR <x_\\d\+\\(D\\)" "forwprop1" } } */
+
+/* { dg-final { cleanup-tree-dump "forwprop1" } } */

Reply via email to