aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPrathamesh Kulkarni <prathamesh.kulkarni@linaro.org>2016-10-17 08:48:43 +0000
committerPrathamesh Kulkarni <prathamesh3492@gcc.gnu.org>2016-10-17 08:48:43 +0000
commit89b80c429a4e09fa8f3ccc1dfc2c2ec17f663d88 (patch)
tree2f792ea3c5eed724349f041f4fc4bb764d9f5cdb /gcc
parentd6b1fea25cf97d8f766dbebc092f4d7b388fc313 (diff)
downloadgcc-89b80c429a4e09fa8f3ccc1dfc2c2ec17f663d88.zip
gcc-89b80c429a4e09fa8f3ccc1dfc2c2ec17f663d88.tar.gz
gcc-89b80c429a4e09fa8f3ccc1dfc2c2ec17f663d88.tar.bz2
re PR tree-optimization/71636 (Missed optimization in variable alignment test)
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/match.pd6
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/pr71636-1.c9
-rw-r--r--gcc/testsuite/gcc.dg/pr71636-2.c12
5 files changed, 37 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index a9b1e3f..9f4ff42 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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
diff --git a/gcc/match.pd b/gcc/match.pd
index e4ff0e7..b782a1e 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -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))
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 92a0a3a..b99ce7b 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 0000000..2df5f96
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr71636-1.c
@@ -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
index 0000000..9e9297d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr71636-2.c
@@ -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" } } */