Message ID | 013801d77bbe$077aa5c0$166ff140$@nextmovesoftware.com |
---|---|
State | New |
Headers | show |
Series | Fold bswap32(x) != 0 to x != 0 (and related transforms) | expand |
On Sun, 18 Jul 2021, Roger Sayle wrote:
> + (if (GIMPLE || !TREE_SIDE_EFFECTS (@0))
I don't think you need to worry about that, the general genmatch machinery
is already supposed to take care of it. All the existing cases in match.pd
are about cond_expr, where counting the occurrences of each @i is not
reliable.
On 7/18/2021 4:03 PM, Marc Glisse wrote: > On Sun, 18 Jul 2021, Roger Sayle wrote: > >> + (if (GIMPLE || !TREE_SIDE_EFFECTS (@0)) > > I don't think you need to worry about that, the general genmatch > machinery is already supposed to take care of it. All the existing > cases in match.pd are about cond_expr, where counting the occurrences > of each @i is not reliable. OK with those tests removed. Jeff
On Mon, Jul 19, 2021 at 12:03 AM Marc Glisse <marc.glisse@inria.fr> wrote: > > On Sun, 18 Jul 2021, Roger Sayle wrote: > > > + (if (GIMPLE || !TREE_SIDE_EFFECTS (@0)) > > I don't think you need to worry about that, the general genmatch machinery > is already supposed to take care of it. All the existing cases in match.pd > are about cond_expr, where counting the occurrences of each @i is not > reliable. Yes, genmatch tries to track omitted and duplicated operands and appropriately preserves side-effects. When you invoke genmatch with -v then you might see warnings like "forcing no side-effects on possibly lost leaf" when it was not possible to see exactly whether a capture was dropped or used multiple times. Richard. > > -- > Marc Glisse
diff --git a/gcc/match.pd b/gcc/match.pd index beb8d27..aa850bb 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3312,6 +3312,25 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) { tree rotate_type = TREE_TYPE (@0); } (convert (rotate (convert:rotate_type @1) @2)))))) +(for cmp (eq ne) + (for rotate (lrotate rrotate) + invrot (rrotate lrotate) + /* (X >>r Y) cmp (Z >>r Y) may simplify to X cmp Y. */ + (simplify + (cmp (rotate @1 @0) (rotate @2 @0)) + (if (GIMPLE || !TREE_SIDE_EFFECTS (@0)) + (cmp @1 @2))) + /* (X >>r C1) cmp C2 may simplify to X cmp C3. */ + (simplify + (cmp (rotate @0 INTEGER_CST@1) INTEGER_CST@2) + (cmp @0 { const_binop (invrot, TREE_TYPE (@0), @2, @1); })) + /* (X >>r Y) cmp C where C is 0 or ~0, may simplify to X cmp C. */ + (simplify + (cmp (rotate @0 @1) INTEGER_CST@2) + (if ((GIMPLE || !TREE_SIDE_EFFECTS (@1)) + && (integer_zerop (@2) || integer_all_onesp (@2))) + (cmp @0 @2))))) + /* Simplifications of conversions. */ /* Basic strip-useless-type-conversions / strip_nops. */ @@ -3622,6 +3641,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (simplify (bswap (bitop:c (bswap @0) @1)) (bitop @0 (bswap @1)))) + (for cmp (eq ne) + (simplify + (cmp (bswap @0) (bswap @1)) + (cmp @0 @1)) + (simplify + (cmp (bswap @0) INTEGER_CST@1) + (cmp @0 (bswap @1)))) /* (bswap(x) >> C1) & C2 can sometimes be simplified to (x >> C3) & C2. */ (simplify (bit_and (convert1? (rshift@0 (convert2? (bswap@4 @1)) INTEGER_CST@2))