Hi,
the Fortran FE sets flag_errno_math and flag_associative_math
https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=94447
https://gcc.gnu.org/viewcvs/gcc?view=revision&revision=159620
Seemingly it (now?) needs to communicate that it is doing so, since otherwise
this is overwritten later on and ignored.
The attached patch does so and comes with two testcases to verify the expected
effect.
The patch has been bootstrapped and regtested on x86_64-unknown-linux-gnu. If
OK, please apply to trunk.
Thanks in advance,
Joost
gcc/fortran/ChangeLog:
2014-05-30 Joost VandeVondele <joost.vandevond...@mat.ethz.ch>
* options.c (gfc_init_options_struct): assert that the frontend sets
flag_errno_math and flag_associative_math.
gcc/testsuite/ChangeLog:
2014-05-30 Joost VandeVondele <joost.vandevond...@mat.ethz.ch>
* gfortran.dg/errnocheck_1.f90: New test.
* gfortran.dg/associative_1.f90: New test.
Index: gcc/fortran/options.c
===================================================================
--- gcc/fortran/options.c (revision 211022)
+++ gcc/fortran/options.c (working copy)
@@ -66,7 +66,9 @@ void
gfc_init_options_struct (struct gcc_options *opts)
{
opts->x_flag_errno_math = 0;
+ opts->frontend_set_flag_errno_math = true;
opts->x_flag_associative_math = -1;
+ opts->frontend_set_flag_associative_math = true;
}
/* Get ready for options handling. Keep in sync with
Index: gcc/testsuite/gfortran.dg/errnocheck_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/errnocheck_1.f90 (revision 0)
+++ gcc/testsuite/gfortran.dg/errnocheck_1.f90 (revision 0)
@@ -0,0 +1,8 @@
+! { dg-do compile { target x86_64-*-* } }
+! Fortran should default to -fno-math-errno
+! and thus no call to sqrt in asm
+subroutine mysqrt(a)
+ real(KIND=KIND(0.0D0)) :: a
+ a=sqrt(a)
+end subroutine
+! { dg-final { scan-assembler-times "call" 0 } }
Index: gcc/testsuite/gfortran.dg/associative_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/associative_1.f90 (revision 0)
+++ gcc/testsuite/gfortran.dg/associative_1.f90 (revision 0)
@@ -0,0 +1,10 @@
+! { dg-do compile }
+! { dg-options "-O1 -fno-signed-zeros -fno-trapping-math -fdump-tree-optimized" }
+! Fortran defaults to associative by default,
+! with -fno-signed-zeros -fno-trapping-math this should optimize away all additions
+SUBROUTINE S1(a)
+ REAL :: a
+ a=1+a-1
+END SUBROUTINE S1
+! { dg-final { scan-tree-dump-times " \\\+ " 0 "optimized" } }
+! { dg-final { cleanup-tree-dump "optimized" } }