Simplify 3*x == 3*y for wrapping types
authorMarc Glisse <marc.glisse@inria.fr>
Wed, 28 Jun 2017 09:22:30 +0000 (11:22 +0200)
committerMarc Glisse <glisse@gcc.gnu.org>
Wed, 28 Jun 2017 09:22:30 +0000 (09:22 +0000)
2017-06-28  Marc Glisse  <marc.glisse@inria.fr>

gcc/
* match.pd ((X & ~Y) | (~X & Y)): Generalize to + and ^.
(x * C EQ/NE y * C): New transformation.

gcc/testsuite/
* gcc.dg/tree-ssa/addadd.c: Remove test duplicated in addadd-2.c.
* gcc.dg/tree-ssa/mulcmp-1.c: New file.

From-SVN: r249732

gcc/ChangeLog
gcc/match.pd
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/addadd.c
gcc/testsuite/gcc.dg/tree-ssa/mulcmp-1.c [new file with mode: 0644]

index d7b45ef8c6de5a35fbcc05850f785aa3d25c27ec..51ce1bfb3482a5be2e9cff0c5fcf3ac5ad8e650e 100644 (file)
@@ -1,3 +1,8 @@
+2017-06-28  Marc Glisse  <marc.glisse@inria.fr>
+
+       * match.pd ((X & ~Y) | (~X & Y)): Generalize to + and ^.
+       (x * C EQ/NE y * C): New transformation.
+
 2017-06-28  Christophe Lyon  <christophe.lyon@linaro.org>
 
        * genmultilib (combination_space): Accept '+' in option names.
index c132cba09cd1faaddf1c68d5dfdc40dbe2c3a06f..ede5504bdf1deccd2a43c8fa115324be8825b7bf 100644 (file)
@@ -642,14 +642,15 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (minus (bit_and:cs @0 @1) (bit_and:cs @0 (bit_not @1)))
   (minus @1 (bit_xor @0 @1)))
 
-/* Simplify (X & ~Y) | (~X & Y) -> X ^ Y.  */
-(simplify
- (bit_ior (bit_and:c @0 (bit_not @1)) (bit_and:c (bit_not @0) @1))
-  (bit_xor @0 @1))
-(simplify
- (bit_ior:c (bit_and @0 INTEGER_CST@2) (bit_and (bit_not @0) INTEGER_CST@1))
- (if (wi::bit_not (@2) == @1)
-  (bit_xor @0 @1)))
+/* Simplify (X & ~Y) |^+ (~X & Y) -> X ^ Y.  */
+(for op (bit_ior bit_xor plus)
+ (simplify
+  (op (bit_and:c @0 (bit_not @1)) (bit_and:c (bit_not @0) @1))
+   (bit_xor @0 @1))
+ (simplify
+  (op:c (bit_and @0 INTEGER_CST@2) (bit_and (bit_not @0) INTEGER_CST@1))
+  (if (wi::bit_not (@2) == @1)
+   (bit_xor @0 @1))))
 
 /* PR53979: Transform ((a ^ b) | a) -> (a | b) */
 (simplify
@@ -1097,6 +1098,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
        && tree_expr_nonzero_p (@1))
    (cmp @0 @2))))
 
+/* For integral types with wrapping overflow and C odd fold
+   x * C EQ/NE y * C into x EQ/NE y.  */
+(for cmp (eq ne)
+ (simplify
+  (cmp (mult @0 INTEGER_CST@1) (mult @2 @1))
+  (if (INTEGRAL_TYPE_P (TREE_TYPE (@1))
+       && TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0))
+       && (TREE_INT_CST_LOW (@1) & 1) != 0)
+   (cmp @0 @2))))
+
 /* For integral types with undefined overflow and C != 0 fold
    x * C RELOP y * C into:
 
index b5d359673992e0f80ec0101e5a05f27c117d2604..2952d5cd5ef7cd291fb2b88340adbd30ab8c9612 100644 (file)
@@ -1,3 +1,8 @@
+2017-06-28  Marc Glisse  <marc.glisse@inria.fr>
+
+       * gcc.dg/tree-ssa/addadd.c: Remove test duplicated in addadd-2.c.
+       * gcc.dg/tree-ssa/mulcmp-1.c: New file.
+
 2017-06-28  Jakub Jelinek  <jakub@redhat.com>
 
        * gcc.target/i386/cmov7.c (sgn): Renamed to ...
index 16474db65658a5e3e88b141b24f991c80936a9e9..454ec2a570db2f1fa555a81757894cb7df205d57 100644 (file)
@@ -23,11 +23,6 @@ int i(int x){
   x += __INT_MAX__;
   return x;
 }
-typedef int S __attribute__((vector_size(16)));
-void j(S*x){
-  *x += __INT_MAX__;
-  *x += __INT_MAX__;
-}
 
 /* { dg-final { scan-tree-dump-times " \\+ 24;" 2 "optimized" } } */
 /* { dg-final { scan-tree-dump-times "\\(unsigned int\\)" 2 "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/mulcmp-1.c b/gcc/testsuite/gcc.dg/tree-ssa/mulcmp-1.c
new file mode 100644 (file)
index 0000000..6ff2ff5
--- /dev/null
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-optimized-raw" } */
+
+int f(unsigned a,unsigned b){
+    a *= 3;
+    b *= 3;
+    return a == b;
+}
+
+/* { dg-final { scan-tree-dump-not "mult_expr" "optimized" } } */