Patchwork Keep -ffp-contract=fast by default if we have -funsafe-math-optimizations

login
register
mail settings
Submitter Ian Bolton
Date March 10, 2014, 10:20 a.m.
Message ID <000301cf3c4a$5328c120$f97a4360$@bolton@arm.com>
Download mbox | patch
Permalink /patch/328528/
State New
Headers show

Comments

Ian Bolton - March 10, 2014, 10:20 a.m.
Hi,

In common.opt, -ffp-contract=fast is set as the default for GCC.  But
then it gets disabled in c-family/c-opts.c if you are using ISO C
(e.g. with -std=c99).

The reason for this patch is that if you have also specified
-funsafe-math-optimizations (or -Ofast or -ffast-math) then it is
likely your preference to have -ffp-contract=fast on, so you can
generate fused multiply adds (fma standard pattern).

This patch works by blocking the override if you have
-funsafe-math-optimizations (directly or indirectly), causing fused
multiply add to be used in the places where we might hope to see it.
(I had considered forcing -ffp-contract=fast on in opts.c if you have
-funsafe-math-optimizations, but it is already on by default ... and
it didn't work either!  The problem is that it is forced off unless
you have explicitly asked for -ffp-contract=fast at the command-line.)

Standard regressions passed.

OK for trunk or stage 1?

Cheers,
Ian


10-03-2014  Ian Bolton  <ian.bolton@arm.com>

        * gcc/c-family/c-opts.c (c_common_post_options): Don't override
        -ffp-contract=fast if unsafe-math-optimizations is on.
Joseph S. Myers - March 11, 2014, 12:27 a.m.
On Mon, 10 Mar 2014, Ian Bolton wrote:

> OK for trunk or stage 1?

OK for trunk with the ChangeLog entry fixed (it's in c-family/ChangeLog, 
so no gcc/c-family/ in the entry itself, and the date should be in 
yyyy-mm-dd format).

Patch

diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
index b7478f3..92ba481 100644
--- a/gcc/c-family/c-opts.c
+++ b/gcc/c-family/c-opts.c
@@ -834,7 +834,8 @@  c_common_post_options (const char **pfilename)
   if (flag_iso
       && !c_dialect_cxx ()
       && (global_options_set.x_flag_fp_contract_mode
-	  == (enum fp_contract_mode) 0))
+	  == (enum fp_contract_mode) 0)
+      && flag_unsafe_math_optimizations == 0)
     flag_fp_contract_mode = FP_CONTRACT_OFF;
 
   /* By default we use C99 inline semantics in GNU99 or C99 mode.  C99