From 15d4fd986330e2e993d0aef0f58d0c5bf7ab0e28 Mon Sep 17 00:00:00 2001 From: Roger Sayle Date: Mon, 14 Apr 2003 20:16:58 +0000 Subject: fold-const.c (fold): Transform (c1 - x) cmp c2... * fold-const.c (fold): Transform (c1 - x) cmp c2, where cmp is a comparison operation and c1/c2 are floating point constants into x swap(cmp) (c1 - c2). * gcc.dg/20030414-2.c: New test case. From-SVN: r65584 --- gcc/fold-const.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'gcc/fold-const.c') diff --git a/gcc/fold-const.c b/gcc/fold-const.c index ebb87e2..95812a2 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -6484,6 +6484,19 @@ fold (expr) && ! TREE_CONSTANT_OVERFLOW (tem)) return fold (build (code, type, TREE_OPERAND (arg0, 0), tem)); + /* Likewise, we can simplify a comparison of a real constant with + a MINUS_EXPR whose first operand is also a real constant, i.e. + (c1 - x) < c2 becomes x > c1-c2. */ + if (flag_unsafe_math_optimizations + && TREE_CODE (arg1) == REAL_CST + && TREE_CODE (arg0) == MINUS_EXPR + && TREE_CODE (TREE_OPERAND (arg0, 0)) == REAL_CST + && 0 != (tem = const_binop (MINUS_EXPR, TREE_OPERAND (arg0, 0), + arg1, 0)) + && ! TREE_CONSTANT_OVERFLOW (tem)) + return fold (build (swap_tree_comparison (code), type, + TREE_OPERAND (arg0, 1), tem)); + /* Fold comparisons against built-in math functions. */ if (TREE_CODE (arg1) == REAL_CST && flag_unsafe_math_optimizations -- cgit v1.1