From: Eric Botcazou Date: Wed, 16 Nov 2005 17:15:23 +0000 (+0000) Subject: fold-const.c (const_binop): Don't constant fold the operation if the result has overf... X-Git-Tag: releases/gcc-4.1.0~753 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=68328cdaefaee1b9e218e08ff2955806ddd20403;p=thirdparty%2Fgcc.git fold-const.c (const_binop): Don't constant fold the operation if the result has overflowed and... * 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0b14036d431b..8fb3e38e8be7 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2005-11-16 Eric Botcazou + + * 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 * config/arm/unwind-arm.c (abort): Add prototype here. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 6f829adfa771..0e74391fe511 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -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 diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index 44a1660e6882..657b2b59c23f 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 22335ac22fc7..9c3f333ddd77 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2005-11-16 Eric Botcazou + + * gcc.dg/fold-overflow-1.c: New test. + 2005-11-16 Daniel Jacobowitz * 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 index 000000000000..2dd2188f8703 --- /dev/null +++ b/gcc/testsuite/gcc.dg/fold-overflow-1.c @@ -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 } } */