re PR tree-optimization/71636 (Missed optimization in variable alignment test)
authorPrathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
Mon, 17 Oct 2016 08:48:43 +0000 (08:48 +0000)
committerPrathamesh Kulkarni <prathamesh3492@gcc.gnu.org>
Mon, 17 Oct 2016 08:48:43 +0000 (08:48 +0000)
2016-10-17  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>

PR tree-optimization/71636
* match.pd (x & ((1 << b) - 1) -> x & ~(~0 << b)): New pattern.

testsuite/
* gcc.dg/pr71636-1.c: New test-case.
* gcc.dg/pr71636-2.c: Likewise.

From-SVN: r241229

gcc/ChangeLog
gcc/match.pd
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr71636-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr71636-2.c [new file with mode: 0644]

index a9b1e3fdacd4fa49d86f93b6c10c98fa8a3ca875..9f4ff42fc298369bb033319fc84941d341ed414d 100644 (file)
@@ -1,3 +1,8 @@
+2016-10-17  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>
+
+       PR tree-optimization/71636
+       * match.pd (x & ((1 << b) - 1) -> x & ~(~0 << b)): New pattern.
+
 2016-10-17  Richard Biener  <rguenther@suse.de>
 
        * gimplify.c (gimplify_function_tree): Do not move the outer
index e4ff0e70588021e933b99bf1a5b2d2c847038777..b782a1ed2f4d5297f17037bd973644567e5c72c6 100644 (file)
@@ -513,6 +513,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (bit_and:c (convert? @0) (convert? (bit_not @0)))
   { build_zero_cst (type); })
 
+/* PR71636: Transform x & ((1U << b) - 1) -> x & ~(~0U << b);  */
+(simplify
+  (bit_and:c @0 (plus:s (lshift:s integer_onep @1) integer_minus_onep))
+  (if (TYPE_UNSIGNED (type))
+    (bit_and @0 (bit_not (lshift { build_all_ones_cst (type); } @1)))))
+
 /* Fold (A & ~B) - (A & B) into (A ^ B) - B.  */
 (simplify
  (minus (bit_and:cs @0 (bit_not @1)) (bit_and:cs @0 @1))
index 92a0a3ad67668f0bd70ef09fe4611180615af94c..b99ce7b6326d5cb36a1824650bda3c63885dc704 100644 (file)
@@ -1,3 +1,8 @@
+2016-10-17  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>
+
+       * gcc.dg/pr71636-1.c: New test-case.
+       * gcc.dg/pr71636-2.c: Likewise.
+
 2016-10-16  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/trampoline3.adb: New test.
diff --git a/gcc/testsuite/gcc.dg/pr71636-1.c b/gcc/testsuite/gcc.dg/pr71636-1.c
new file mode 100644 (file)
index 0000000..2df5f96
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-do compile } */
+/* { dg-options "-fdump-tree-gimple" } */
+
+unsigned f(unsigned x, unsigned b)
+{
+  return x & ((1U << b) - 1);
+}
+
+/* { dg-final { scan-tree-dump-not "1 <<" "gimple" } } */
diff --git a/gcc/testsuite/gcc.dg/pr71636-2.c b/gcc/testsuite/gcc.dg/pr71636-2.c
new file mode 100644 (file)
index 0000000..9e9297d
--- /dev/null
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-forwprop-details" } */
+
+unsigned f(unsigned x, unsigned b)
+{
+  unsigned t1 = 1U << b;
+  unsigned t2 = t1 - 1;
+  unsigned t3 = x & t2;
+  return t3;
+}
+
+/* { dg-final { scan-tree-dump "_\[0-9\] = ~_\[0-9\]" "forwprop1" } } */