aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorAndrew Pinski <pinskia@physics.uc.edu>2005-07-02 16:24:31 +0000
committerAndrew Pinski <pinskia@gcc.gnu.org>2005-07-02 09:24:31 -0700
commit70a9e64b3cc4c27d53dd895e5318cae00245b22c (patch)
tree6727f44f38b7555600e9d6975c1b06de203f7e6f /gcc/fold-const.c
parent2d0dab7f2bb2acbc9a9fffc7278be44c9a1dcd43 (diff)
downloadgcc-70a9e64b3cc4c27d53dd895e5318cae00245b22c.zip
gcc-70a9e64b3cc4c27d53dd895e5318cae00245b22c.tar.gz
gcc-70a9e64b3cc4c27d53dd895e5318cae00245b22c.tar.bz2
re PR tree-optimization/14490 ([tree-ssa] Simplify "a - 10 > 150" into "a > 160")
2005-07-02 Andrew Pinski <pinskia@physics.uc.edu> PR middle-end/14490 * fold-const.c (fold_binary): Handle the return value of fold_to_nonsharp_ineq_using_bound if we get back the same operand back. Implement "X +- C1 CMP C2" folding to "X CMP C2 -+ C1". From-SVN: r101535
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 564cec3..682ae00 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -8575,11 +8575,11 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
&& !TREE_SIDE_EFFECTS (arg1))
{
tem = fold_to_nonsharp_ineq_using_bound (arg0, arg1);
- if (tem)
+ if (tem && !operand_equal_p (tem, arg0, 0))
return fold_build2 (code, type, tem, arg1);
tem = fold_to_nonsharp_ineq_using_bound (arg1, arg0);
- if (tem)
+ if (tem && !operand_equal_p (tem, arg1, 0))
return fold_build2 (code, type, arg0, tem);
}
@@ -8865,6 +8865,30 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
}
}
+ /* Transform comparisons of the form X +- C1 CMP C2 to X CMP C2 +- C1. */
+ if ((TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MINUS_EXPR)
+ && (TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST
+ && !TREE_OVERFLOW (TREE_OPERAND (arg0, 1))
+ && !TYPE_UNSIGNED (TREE_TYPE (arg1))
+ && !(flag_wrapv || flag_trapv))
+ && (TREE_CODE (arg1) == INTEGER_CST
+ && !TREE_OVERFLOW (arg1)))
+ {
+ tree const1 = TREE_OPERAND (arg0, 1);
+ tree const2 = arg1;
+ tree variable = TREE_OPERAND (arg0, 0);
+ tree lhs;
+ int lhs_add;
+ lhs_add = TREE_CODE (arg0) != PLUS_EXPR;
+
+ lhs = fold_build2 (lhs_add ? PLUS_EXPR : MINUS_EXPR,
+ TREE_TYPE (arg1), const2, const1);
+ if (TREE_CODE (lhs) == TREE_CODE (arg1)
+ && (TREE_CODE (lhs) != INTEGER_CST
+ || !TREE_OVERFLOW (lhs)))
+ return fold_build2 (code, type, variable, lhs);
+ }
+
if (FLOAT_TYPE_P (TREE_TYPE (arg0)))
{
tree targ0 = strip_float_extensions (arg0);