re PR tree-optimization/91504 (Inlining misses some logical operation folding)
authorKamlesh Kumar <kamleshbhalui@gmail.com>
Tue, 3 Sep 2019 20:13:22 +0000 (20:13 +0000)
committerJeff Law <law@gcc.gnu.org>
Tue, 3 Sep 2019 20:13:22 +0000 (14:13 -0600)
PR tree-optimization/91504
* match.pd: Add ((~a & b) ^a) --> (a | b).

        PR tree-optimization/91504
gcc.dg/tree-ssa/pr91504.c: New test.

From-SVN: r275354

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

index 6ac810fca55530fa9b8adc91451d6bd756ae8fab..abbbf16781f307f2bf5c6618c36d755cdcfb896f 100644 (file)
@@ -1,3 +1,8 @@
+2019-09-03  Kamlesh Kumar  <kamleshbhalui@gmail.com>
+
+       PR tree-optimization/91504
+       * match.pd: Add ((~a & b) ^a) --> (a | b).
+
 2019-09-03  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/91604
index cd75dacd9cd4a3caf66d8c18e09e7edc2a02758d..1d13543a6159dc94ce1ff1112c0bfc6b0d588638 100644 (file)
@@ -831,6 +831,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (bit_xor:c (bit_and:cs @0 (bit_not @1)) (bit_not @0))
  (bit_not (bit_and @0 @1)))
 
+/* (~a & b) ^ a  -->   (a | b)   */
+(simplify
+ (bit_xor:c (bit_and:cs (bit_not @0) @1) @0)
+ (bit_ior @0 @1))
+
 /* (a | b) & ~(a ^ b)  -->  a & b  */
 (simplify
  (bit_and:c (bit_ior @0 @1) (bit_not (bit_xor:c @0 @1)))
index 44c43d26b938618ba821e183e7c3c89022434740..4cf3e9b1ec411b1e9f800fbb50d49ce9acd5faf0 100644 (file)
@@ -1,3 +1,8 @@
+2019-09-03  Kamlesh Kumar  <kamleshbhalui@gmail.com>
+
+        PR tree-optimization/91504
+       gcc.dg/tree-ssa/pr91504.c: New test.
+
 2019-09-03  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/91604
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr91504.c b/gcc/testsuite/gcc.dg/tree-ssa/pr91504.c
new file mode 100644 (file)
index 0000000..a52dea4
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-optimized-raw" } */
+
+static inline unsigned deposit32(unsigned value, int start, int length,
+                                 unsigned fieldval)
+{
+    unsigned mask = (~0U >> (32 - length)) << start;
+    return (value & ~mask) | ((fieldval << start) & mask);
+}
+
+unsigned foo(unsigned value)
+{
+   return deposit32(value, 10, 1, 1);
+}
+
+/* { dg-final { scan-tree-dump-not "bit_and_expr" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "bit_xor_expr" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "bit_not_expr" "optimized" } } */