+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
(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))
+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.
--- /dev/null
+/* { 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" } } */
--- /dev/null
+/* { 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" } } */