> Am 21.11.2026 um 11:23 schrieb Thomas Koenig <[email protected]>:
> 
> Hello world,
> 
> I have looked at reassociation for a bit. Fortran allows expressions to
> be reassociated, but parentheses must be honored. This we do (at least as
> long as -fprotect-parens is in force). But Fortran forbids reassociation
> across different expressions or statements, and we do that with
> -freassociative-math.
> 
> An example:
> 
> 
> real(8) function add_v2 (a,b,c,d) result(res)
>  real(8), value :: a, b, c, d
>  real(8) :: tmp
>  tmp = a + b
>  tmp = tmp + c
>  res = tmp + d
> end function add_v2
> 
> is translated to
> 
> add_v2_:
> .LFB5:
>    addsd    %xmm3, %xmm2
>    addsd    %xmm1, %xmm0
>    addsd    %xmm2, %xmm0
>    ret
> 
> so it is evaluated as (a + b) + (c + d). This is faster when there are
> parallel or pipelined adders, but non-conforming.

That means the Frontend stops emitting PAREN_EXPR when -fassoicative-math?  
Because the middle-end should still honor those in that case.  IIRC only -Ofast 
and possibly -fast-math implicitly add -fno-protect-parens 

> Also, gcc never reassociates integer expressions, which we are allowed
> to do under Fortran rules.
> 
> So, what would you think of a project to create Fortran-conforming
> reassociation, and also make it the default? Certainly too late for
> now, but it could be something to be merged early stage one.
> 
> Comments?
> 
> Best regards
> 
>    Thomas
> 

Reply via email to