diff options
author | Jakub Jelinek <jakub@redhat.com> | 2019-12-03 10:20:43 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2019-12-03 10:20:43 +0100 |
commit | 129bd066049f065e522990e63bb10ff92b3c018d (patch) | |
tree | 0e87242b0d74bc021daa843f615ce50227404735 /gcc/match.pd | |
parent | a4c772e26dabdf8e2bf2d26d0d7f8e60d97f3f4e (diff) |
re PR tree-optimization/92734 (Missing match.pd simplification done by fold_binary_loc on generic)
PR tree-optimization/92734
* match.pd ((CST1 - A) +- CST2 -> CST3 - A,
CST1 - (CST2 - A) -> CST3 + A): Handle nop casts around
inner subtraction.
* gcc.dg/tree-ssa/pr92734.c: New test.
From-SVN: r278925
Diffstat (limited to 'gcc/match.pd')
-rw-r--r-- | gcc/match.pd | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/gcc/match.pd b/gcc/match.pd index 14f6a9d5078..d3312e5f279 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2237,17 +2237,39 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* (CST1 - A) +- CST2 -> CST3 - A */ (for outer_op (plus minus) (simplify - (outer_op (minus CONSTANT_CLASS_P@1 @0) CONSTANT_CLASS_P@2) - (with { tree cst = const_binop (outer_op, type, @1, @2); } - (if (cst && !TREE_OVERFLOW (cst)) - (minus { cst; } @0))))) - - /* CST1 - (CST2 - A) -> CST3 + A */ + (outer_op (nop_convert (minus CONSTANT_CLASS_P@1 @0)) CONSTANT_CLASS_P@2) + /* If one of the types wraps, use that one. */ + (if (!ANY_INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_WRAPS (type)) + /* If all 3 captures are CONSTANT_CLASS_P, punt, as we might recurse + forever if something doesn't simplify into a constant. */ + (if (!CONSTANT_CLASS_P (@0)) + (minus (outer_op (view_convert @1) @2) (view_convert @0))) + (if (!ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0)) + || TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0))) + (view_convert (minus (outer_op @1 (view_convert @2)) @0)) + (if (types_match (type, @0)) + (with { tree cst = const_binop (outer_op, type, @1, @2); } + (if (cst && !TREE_OVERFLOW (cst)) + (minus { cst; } @0)))))))) + + /* CST1 - (CST2 - A) -> CST3 + A + Use view_convert because it is safe for vectors and equivalent for + scalars. */ (simplify - (minus CONSTANT_CLASS_P@1 (minus CONSTANT_CLASS_P@2 @0)) - (with { tree cst = const_binop (MINUS_EXPR, type, @1, @2); } - (if (cst && !TREE_OVERFLOW (cst)) - (plus { cst; } @0)))) + (minus CONSTANT_CLASS_P@1 (nop_convert (minus CONSTANT_CLASS_P@2 @0))) + /* If one of the types wraps, use that one. */ + (if (!ANY_INTEGRAL_TYPE_P (type) || TYPE_OVERFLOW_WRAPS (type)) + /* If all 3 captures are CONSTANT_CLASS_P, punt, as we might recurse + forever if something doesn't simplify into a constant. */ + (if (!CONSTANT_CLASS_P (@0)) + (plus (view_convert @0) (minus @1 (view_convert @2)))) + (if (!ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0)) + || TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0))) + (view_convert (plus @0 (minus (view_convert @1) @2))) + (if (types_match (type, @0)) + (with { tree cst = const_binop (MINUS_EXPR, type, @1, @2); } + (if (cst && !TREE_OVERFLOW (cst)) + (plus { cst; } @0))))))) /* ((T)(A)) + CST -> (T)(A + CST) */ #if GIMPLE |