diff options
author | Roger Sayle <roger@eyesopen.com> | 2002-06-01 16:56:08 +0000 |
---|---|---|
committer | Roger Sayle <sayle@gcc.gnu.org> | 2002-06-01 16:56:08 +0000 |
commit | 378393da613d7c182ce3370696ec47a5a5cb2aef (patch) | |
tree | c7cb5d93af1f6099cec88dc9bb98ff85b1058671 /gcc/fold-const.c | |
parent | 01c58f2670a5f7858b8762e06cab0a68b98a684f (diff) | |
download | gcc-378393da613d7c182ce3370696ec47a5a5cb2aef.zip gcc-378393da613d7c182ce3370696ec47a5a5cb2aef.tar.gz gcc-378393da613d7c182ce3370696ec47a5a5cb2aef.tar.bz2 |
tree.c (real_minus_onep): New function to test for -1.0.
* tree.c (real_minus_onep): New function to test for -1.0.
* fold-const.c (fold) [MULT_EXPR]: Optimize -1.0*x into -x.
* gcc.dg/fnegate-1.c: New test case.
From-SVN: r54149
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 0998a93..947d575 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -5370,6 +5370,14 @@ fold (expr) so we can do this anyway. */ if (real_onep (arg1)) return non_lvalue (convert (type, arg0)); + + /* Transform x * -1.0 into -x. This should be safe for NaNs, + signed zeros and signed infinities, but is currently + restricted to "unsafe math optimizations" just in case. */ + if (flag_unsafe_math_optimizations + && real_minus_onep (arg1)) + return fold (build1 (NEGATE_EXPR, type, arg0)); + /* x*2 is x+x */ if (! wins && real_twop (arg1) && (*lang_hooks.decls.global_bindings_p) () == 0 |