diff options
author | sayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-04-14 20:16:58 +0000 |
---|---|---|
committer | sayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-04-14 20:16:58 +0000 |
commit | edc21ba8088e0e485b3bdccaba28005747e2ba61 (patch) | |
tree | a3d2d13cfa04d1656aee06fd96e6f08bdbc67e20 | |
parent | 6419e9ffc71872b1286b807082d907e644e84122 (diff) | |
download | gcc-edc21ba8088e0e485b3bdccaba28005747e2ba61.tar.gz |
* 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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@65584 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/fold-const.c | 13 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/20030414-2.c | 38 |
4 files changed, 62 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 05b01f98a32..bf118416c75 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2003-04-14 Roger Sayle <roger@eyesopen.com> + + * 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). + 2003-04-14 Vladimir Makarov <vmakarov@redhat.com> * genautomata.c (output_translate_vect): Fix a typo in loop @@ -1376,7 +1382,7 @@ Thu Apr 3 00:18:49 CEST 2003 Jan Hubicka <jh@suse.cz> 2003-04-01 Roger Sayle <roger@eyesopen.com> PR fortran/9974 - * gcse.c (reg_killed_on_egde): New function to test whether the + * gcse.c (reg_killed_on_edge): New function to test whether the given reg is overwritten by any instruction queued on an edge. (bypass_block): Ignore substitutions killed on incoming edges. Don't bypass outgoing edges that have queued instructions. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index ebb87e27a5e..95812a2e13c 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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 214ed1a2075..1fc22eecce1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2003-04-14 Roger Sayle <roger@eyesopen.com> + + * gcc.dg/20030414-2.c: New test case. + 2003-04-14 Hans-Peter Nilsson <hp@axis.com> PR target/10377 diff --git a/gcc/testsuite/gcc.dg/20030414-2.c b/gcc/testsuite/gcc.dg/20030414-2.c new file mode 100644 index 00000000000..f4eb8bf36ec --- /dev/null +++ b/gcc/testsuite/gcc.dg/20030414-2.c @@ -0,0 +1,38 @@ +/* Copyright (C) 2003 Free Software Foundation. + + Check that constant folding (c1 - x) op c2 into x swap(op) c1-c2 + doesn't break anything. + + Written by Roger Sayle, 27th March 2003. */ + +/* { dg-do run } */ +/* { dg-options "-O2 -ffast-math" } */ + +extern void abort (void); + +int foo(double x) +{ + return (10.0 - x) > 3.0; +} + +int bar (double x) +{ + return (10.0 - x) == 5.0; +} + +int main() +{ + if (foo (8.0)) + abort (); + + if (! foo (6.0)) + abort (); + + if (bar (1.0)) + abort (); + + if (! bar (5.0)) + abort (); + return 0; +} + |