public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [PATCH, Fortan] fix initialization of flag_errno_math and flag_associative_math
@ 2014-06-02 20:15 FX
  2014-06-05 12:54 ` VandeVondele  Joost
  0 siblings, 1 reply; 13+ messages in thread
From: FX @ 2014-06-02 20:15 UTC (permalink / raw)
  To: gfortran, gcc-patches, joost.vandevondele, Dominique Dhumieres

> Why do you want -fno-math-errno to be the default for gfortran?
> AFAICT such default is not documented and the flag works
> (checked on your test gfortran.dg/errnocheck_1.f90).

It should be the default, and it used to be. Fortran doesn’t care about math routines setting errno (its existence is specified in C & C++ standards, but not in the Fortran standard). If I understand correctly, Joost’s patch just adapts this to a new flag handling mechanism.

FX

^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: [PATCH, Fortan] fix initialization of flag_errno_math and flag_associative_math
@ 2014-05-31 11:01 Dominique Dhumieres
  2014-06-02  6:08 ` VandeVondele  Joost
  0 siblings, 1 reply; 13+ messages in thread
From: Dominique Dhumieres @ 2014-05-31 11:01 UTC (permalink / raw)
  To: fortran; +Cc: gcc-patches, joost.vandevondele

Hi Joost,

Why do you want -fno-math-errno to be the default for gfortran?
AFAICT such default is not documented and the flag works
(checked on your test gfortran.dg/errnocheck_1.f90).

For -fassociative-math, the manual says

For Fortran the option is automatically enabled when both -fno-signed-zeros and -fno-trapping-math are in effect.

and again AFAICT this is not working (checked on your test
gfortran.dg/associative_1.f90) while I see

  /* Fortran allows associative math - but we cannot reassociate if
     we want traps or signed zeros. Cf. also flag_protect_parens.  */
  if (flag_associative_math == -1)
    flag_associative_math = (!flag_trapping_math && !flag_signed_zeros);

in gcc/fortran/options.c. Why this is not working is beyond my understanding,
but I am not sure that your fix is the right one.

Cheers,

Dominique

^ permalink raw reply	[flat|nested] 13+ messages in thread
* [PATCH, Fortan] fix initialization of flag_errno_math and flag_associative_math
@ 2014-05-30 19:22 VandeVondele  Joost
  2014-08-18 15:48 ` VandeVondele  Joost
  0 siblings, 1 reply; 13+ messages in thread
From: VandeVondele  Joost @ 2014-05-30 19:22 UTC (permalink / raw)
  To: fortran; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 548 bytes --]

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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch-math-errno-associative.diff --]
[-- Type: text/x-patch; name="patch-math-errno-associative.diff", Size: 2053 bytes --]

gcc/fortran/ChangeLog:

2014-05-30 Joost VandeVondele  <Joost.VandeVondele@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.VandeVondele@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" } }

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2014-08-20  7:10 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-02 20:15 [PATCH, Fortan] fix initialization of flag_errno_math and flag_associative_math FX
2014-06-05 12:54 ` VandeVondele  Joost
2014-06-05 13:07   ` Janne Blomqvist
2014-06-05 14:37     ` Dominique Dhumieres
2014-07-30 14:04       ` VandeVondele  Joost
  -- strict thread matches above, loose matches on Subject: below --
2014-05-31 11:01 Dominique Dhumieres
2014-06-02  6:08 ` VandeVondele  Joost
2014-05-30 19:22 VandeVondele  Joost
2014-08-18 15:48 ` VandeVondele  Joost
2014-08-19 10:04   ` Janne Blomqvist
2014-08-19 10:07     ` VandeVondele  Joost
2014-08-19 10:28       ` Janne Blomqvist
2014-08-20  7:10         ` VandeVondele  Joost

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).