[PATCH][match-and-simplify] Finish simplify_bitwise_binary patterns
Richard Biener
rguenther@suse.de
Fri Sep 12 11:36:00 GMT 2014
On Fri, 12 Sep 2014, Marc Glisse wrote:
> On Fri, 12 Sep 2014, Richard Biener wrote:
>
> > +/* x ^ ~0 -> ~x */
> > (simplify
> > (bit_and @0 integer_all_onesp)
> > @0)
>
> The comment doesn't seem to match.
Thanks - fixed below which also implements simplify_mult and
simplify_not_neg_expr.
Committed.
Richard.
2014-09-12 Richard Biener <rguenther@suse.de>
* match-constant-folding.pd (x & ~0 -> x): Move ...
* match-bitwise.pd: ... here. Implement simplify_not_neg_expr.
* match-plusminus.pd: Likewise. Implement simplify_mult.
Index: gcc/match-bitwise.pd
===================================================================
--- gcc/match-bitwise.pd (revision 215212)
+++ gcc/match-bitwise.pd (working copy)
@@ -135,10 +135,23 @@ along with GCC; see the file COPYING3.
&& TYPE_PRECISION (TREE_TYPE (@1)) == 1)
(le @0 @1)))
+/* From tree-ssa-forwprop.c:simplify_not_neg_expr. */
+
+/* ~~x -> x */
+(simplify
+ (bit_not (bit_not @0))
+ @0)
+/* The corresponding (negate (negate @0)) -> @0 is in match-plusminus.pd. */
+
/* End of known transform origin. Note that some bitwise transforms
are handled in match-constant-folding.pd. */
+/* x & ~0 -> x */
+(simplify
+ (bit_and @0 integer_all_onesp)
+ @0)
+
/* ~x & ~y -> ~(x | y) */
(simplify
(bit_and (bit_not @0) (bit_not @1))
@@ -149,11 +162,6 @@ along with GCC; see the file COPYING3.
(bit_ior (bit_not @0) (bit_not @1))
(bit_not (bit_and @0 @1)))
-/* ~~x -> x */
-(simplify
- (bit_not (bit_not @0))
- @0)
-
/* Simple association cases that cancel one operand. */
/* ((a OP b) & ~a) -> (b & ~a) OP 0 */
Index: gcc/match-plusminus.pd
===================================================================
--- gcc/match-plusminus.pd (revision 215212)
+++ gcc/match-plusminus.pd (working copy)
@@ -30,6 +30,10 @@ along with GCC; see the file COPYING3.
(simplify
(minus @0 (negate @1))
(plus @0 @1))
+ /* From tree-ssa-forwprop.c:simplify_not_neg_expr. */
+ (simplify
+ (negate (negate @1))
+ @1)
/* We can't reassociate floating-point or fixed-point plus or minus
because of saturation to +-Inf. */
@@ -155,3 +159,13 @@ along with GCC; see the file COPYING3.
(pointer_plus @0 (negate (bit_and (convert @0) INTEGER_CST@1)))
(with { tree algn = wide_int_to_tree (TREE_TYPE (@0), wi::bit_not (@1)); }
(bit_and @0 { algn; })))
+
+
+/* From tree-ssa-forwprop.c:simplify_mult. */
+
+/* (X /[ex] A) * A -> X. */
+(simplify
+ (mult (convert? (exact_div @0 @1)) @1)
+ /* Look through a sign-changing conversion. */
+ (if (TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION (type))
+ (convert @0)))
Index: gcc/match-constant-folding.pd
===================================================================
--- gcc/match-constant-folding.pd (revision 215212)
+++ gcc/match-constant-folding.pd (working copy)
@@ -60,11 +60,6 @@ along with GCC; see the file COPYING3.
(bit_ior @0 integer_all_onesp@1)
@1)
-/* x ^ ~0 -> ~x */
-(simplify
- (bit_and @0 integer_all_onesp)
- @0)
-
/* x & 0 -> 0 */
(simplify
(bit_and @0 integer_zerop@1)
More information about the Gcc-patches
mailing list