public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [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

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

ping ?

https://gcc.gnu.org/ml/fortran/2014-05/msg00162.html

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

* Re: [PATCH, Fortan] fix initialization of flag_errno_math and flag_associative_math
  2014-08-18 15:48 ` VandeVondele  Joost
@ 2014-08-19 10:04   ` Janne Blomqvist
  2014-08-19 10:07     ` VandeVondele  Joost
  0 siblings, 1 reply; 13+ messages in thread
From: Janne Blomqvist @ 2014-08-19 10:04 UTC (permalink / raw)
  To: VandeVondele Joost; +Cc: fortran, gcc-patches

On Mon, Aug 18, 2014 at 6:48 PM, VandeVondele  Joost
<joost.vandevondele@mat.ethz.ch> wrote:
> ping ?
>
> https://gcc.gnu.org/ml/fortran/2014-05/msg00162.html

Ok, again. If Dominique comes up with some reason why the patch should
be modified, it can be done then. AFAICT your patch is better than the
status quo.


-- 
Janne Blomqvist

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

* RE: [PATCH, Fortan] fix initialization of flag_errno_math and flag_associative_math
  2014-08-19 10:04   ` Janne Blomqvist
@ 2014-08-19 10:07     ` VandeVondele  Joost
  2014-08-19 10:28       ` Janne Blomqvist
  0 siblings, 1 reply; 13+ messages in thread
From: VandeVondele  Joost @ 2014-08-19 10:07 UTC (permalink / raw)
  To: Janne Blomqvist; +Cc: fortran, gcc-patches

Thanks, can somebody with svn write access commit ?

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

* Re: [PATCH, Fortan] fix initialization of flag_errno_math and flag_associative_math
  2014-08-19 10:07     ` VandeVondele  Joost
@ 2014-08-19 10:28       ` Janne Blomqvist
  2014-08-20  7:10         ` VandeVondele  Joost
  0 siblings, 1 reply; 13+ messages in thread
From: Janne Blomqvist @ 2014-08-19 10:28 UTC (permalink / raw)
  To: VandeVondele Joost; +Cc: fortran, gcc-patches

On Tue, Aug 19, 2014 at 1:07 PM, VandeVondele  Joost
<joost.vandevondele@mat.ethz.ch> wrote:
> Thanks, can somebody with svn write access commit ?

Please get yourself write-after-approval access per instructions at
https://gcc.gnu.org/svnwrite.html . You can use me as your sponsor.
Thanks.

-- 
Janne Blomqvist

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

* RE: [PATCH, Fortan] fix initialization of flag_errno_math and flag_associative_math
  2014-08-19 10:28       ` Janne Blomqvist
@ 2014-08-20  7:10         ` VandeVondele  Joost
  0 siblings, 0 replies; 13+ messages in thread
From: VandeVondele  Joost @ 2014-08-20  7:10 UTC (permalink / raw)
  To: Janne Blomqvist; +Cc: fortran, gcc-patches

Committed revision 214211.

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

* RE: [PATCH, Fortan] fix initialization of flag_errno_math and flag_associative_math
  2014-06-05 14:37     ` Dominique Dhumieres
@ 2014-07-30 14:04       ` VandeVondele  Joost
  0 siblings, 0 replies; 13+ messages in thread
From: VandeVondele  Joost @ 2014-07-30 14:04 UTC (permalink / raw)
  To: Dominique Dhumieres, blomqvist.janne; +Cc: gcc-patches, fxcoudert, fortran

Dominque, 

after Janne's OK, and FX judgement, I wonder if you have reached a conclusion. If so, the fsf assignment is now complete, and the patch could be applied.

Joost

> Ok for trunk. Thanks!

Please don't rush! The behavior of -fno-signed-zeros -fno-trapping-math
implying associative math has been changed (as in reverted) between r165758
(implied associative math) and r165930 (lost associative math). AFAICT
it could be due to 165823. Investigating! I am also lookinf for the introduction
of *frontend_set*.

TIA

Dominique

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

* Re: [PATCH, Fortan] fix initialization of flag_errno_math and flag_associative_math
  2014-06-05 13:07   ` Janne Blomqvist
@ 2014-06-05 14:37     ` Dominique Dhumieres
  2014-07-30 14:04       ` VandeVondele  Joost
  0 siblings, 1 reply; 13+ messages in thread
From: Dominique Dhumieres @ 2014-06-05 14:37 UTC (permalink / raw)
  To: joost.vandevondele, blomqvist.janne
  Cc: gcc-patches, fxcoudert, fortran, dominiq

> Ok for trunk. Thanks!

Please don't rush! The behavior of -fno-signed-zeros -fno-trapping-math
implying associative math has been changed (as in reverted) between r165758
(implied associative math) and r165930 (lost associative math). AFAICT
it could be due to 165823. Investigating! I am also lookinf for the introduction
of *frontend_set*.

TIA

Dominique

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

* Re: [PATCH, Fortan] fix initialization of flag_errno_math and flag_associative_math
  2014-06-05 12:54 ` VandeVondele  Joost
@ 2014-06-05 13:07   ` Janne Blomqvist
  2014-06-05 14:37     ` Dominique Dhumieres
  0 siblings, 1 reply; 13+ messages in thread
From: Janne Blomqvist @ 2014-06-05 13:07 UTC (permalink / raw)
  To: VandeVondele Joost; +Cc: FX, gfortran, gcc-patches, Dominique Dhumieres

On Thu, Jun 5, 2014 at 3:54 PM, VandeVondele  Joost
<joost.vandevondele@mat.ethz.ch> wrote:
> I have now verified that both new testcases indeed pass with
>
> gcc version 4.6.0 20100520 (experimental) [trunk revision 159620] (GCC)
>
> that is the revision where Tobias enabled associative math by default. So that this patch fixes a regression.

Ok for trunk. Thanks!


-- 
Janne Blomqvist

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

* 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
  2014-06-05 13:07   ` Janne Blomqvist
  0 siblings, 1 reply; 13+ messages in thread
From: VandeVondele  Joost @ 2014-06-05 12:54 UTC (permalink / raw)
  To: FX, gfortran, gcc-patches, Dominique Dhumieres

I have now verified that both new testcases indeed pass with

gcc version 4.6.0 20100520 (experimental) [trunk revision 159620] (GCC)

that is the revision where Tobias enabled associative math by default. So that this patch fixes a regression.  

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

* 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, 0 replies; 13+ messages in thread
From: VandeVondele  Joost @ 2014-06-02  6:08 UTC (permalink / raw)
  To: Dominique Dhumieres, fortran; +Cc: gcc-patches

> Why do you want -fno-math-errno to be the default for gfortran?

because it was with rth's commit? This makes sense also because errno is a variable that is defined for C, and not accessible from Fortran. Why would you want -fmath-errno to be the default ?

>  if (flag_associative_math == -1)
>    flag_associative_math = (!flag_trapping_math && !flag_signed_zeros);

> Why this is not working is beyond my understanding, but I am not sure that your fix is the right one.

while the details of the option handling are rather opaque to me to, at the point of reaching this statement, flag_associative_math currently equals 0 or 1 even if the user didn't specify the flag. I believe as set by common_handle_option. With my patch, the value of -1 is seen when the user did not specify the flag explicitly.

Note that the go frontend uses a similar approach for errno.

Joost

^ 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

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-05-30 19:22 [PATCH, Fortan] fix initialization of flag_errno_math and flag_associative_math 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
2014-05-31 11:01 Dominique Dhumieres
2014-06-02  6:08 ` VandeVondele  Joost
2014-06-02 20:15 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

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).