]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
fold-const.c (const_binop): Don't constant fold the operation if the result has overf...
authorEric Botcazou <ebotcazou@adacore.com>
Wed, 16 Nov 2005 17:15:23 +0000 (17:15 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Wed, 16 Nov 2005 17:15:23 +0000 (17:15 +0000)
* fold-const.c (const_binop): Don't constant fold the operation
if the result has overflowed and flag_trapping_math.
* simplify-rtx.c (simplify_const_binary_operation): Likewise.

From-SVN: r107092

gcc/ChangeLog
gcc/fold-const.c
gcc/simplify-rtx.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/fold-overflow-1.c [new file with mode: 0644]

index 0b14036d431b8a123d0cc82117ebe4923b65bc30..8fb3e38e8be770ed509dd2e1d25a9b70ce3b7867 100644 (file)
@@ -1,3 +1,9 @@
+2005-11-16  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * fold-const.c (const_binop): Don't constant fold the operation
+       if the result has overflowed and flag_trapping_math.
+       * simplify-rtx.c (simplify_const_binary_operation): Likewise.
+
 2005-11-16  Daniel Jacobowitz  <dan@codesourcery.com>
 
        * config/arm/unwind-arm.c (abort): Add prototype here.
index 6f829adfa7714a6772cc49a549c14ece905a5460..0e74391fe511a9b1c36a1f5c43b46c17211d79f6 100644 (file)
@@ -1537,6 +1537,16 @@ const_binop (enum tree_code code, tree arg1, tree arg2, int notrunc)
       inexact = real_arithmetic (&value, code, &d1, &d2);
       real_convert (&result, mode, &value);
 
+      /* Don't constant fold this floating point operation if
+        the result has overflowed and flag_trapping_math.  */
+
+      if (flag_trapping_math
+         && MODE_HAS_INFINITIES (mode)
+         && REAL_VALUE_ISINF (result)
+         && !REAL_VALUE_ISINF (d1)
+         && !REAL_VALUE_ISINF (d2))
+       return NULL_TREE;
+
       /* Don't constant fold this floating point operation if the
         result may dependent upon the run-time rounding mode and
         flag_rounding_math is set, or if GCC's software emulation
index 44a1660e6882477101a18beb76058ed2924f20b1..657b2b59c23f7df0c842c23d1d308b583ba030f9 100644 (file)
@@ -2242,6 +2242,17 @@ simplify_const_binary_operation (enum rtx_code code, enum machine_mode mode,
                                     &f0, &f1);
          real_convert (&result, mode, &value);
 
+         /* Don't constant fold this floating point operation if
+            the result has overflowed and flag_trapping_math.  */
+
+         if (flag_trapping_math
+             && MODE_HAS_INFINITIES (mode)
+             && REAL_VALUE_ISINF (result)
+             && !REAL_VALUE_ISINF (f0)
+             && !REAL_VALUE_ISINF (f1))
+           /* Overflow plus exception.  */
+           return 0;
+
          /* Don't constant fold this floating point operation if the
             result may dependent upon the run-time rounding mode and
             flag_rounding_math is set, or if GCC's software emulation
index 22335ac22fc710c4d6dc3865314af1bf11c9a953..9c3f333ddd77338548feeacc455c799ab2731d02 100644 (file)
@@ -1,3 +1,7 @@
+2005-11-16  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gcc.dg/fold-overflow-1.c: New test.
+
 2005-11-16  Daniel Jacobowitz  <dan@codesourcery.com>
 
        * gcc.dg/cleanup-5.c, gcc.dg/cleanup-8.c, gcc.dg/cleanup-9.c,
diff --git a/gcc/testsuite/gcc.dg/fold-overflow-1.c b/gcc/testsuite/gcc.dg/fold-overflow-1.c
new file mode 100644 (file)
index 0000000..2dd2188
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-compile } */
+/* { dg-options "-O -ftrapping-math" } */
+
+float f1 =  __FLT_MAX__ + __FLT_MAX__;
+
+float foo1(void)
+{
+  return  __FLT_MAX__ + __FLT_MAX__;
+}
+
+float f2 = 1.0f/0.0f;
+
+float foo2(void)
+{
+  return 1.0f/0.0f;
+}
+
+/* { dg-final { scan-assembler-times "2139095040" 2 } } */