public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/115563] New: Unnecessary brackets prevent fortran vectorisation
@ 2024-06-20 17:56 mjr19 at cam dot ac.uk
2024-06-20 18:01 ` [Bug fortran/115563] " pinskia at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: mjr19 at cam dot ac.uk @ 2024-06-20 17:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115563
Bug ID: 115563
Summary: Unnecessary brackets prevent fortran vectorisation
Product: gcc
Version: 14.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: mjr19 at cam dot ac.uk
Target Milestone: ---
The code
subroutine foo(a,n)
complex (kind(1d0)) :: a(*)
integer :: i,n
!$OMP SIMD
do i=1,n
a(i)=(a(i)+(6d0,1d0))
enddo
end subroutine foo
compiled with
$ gfortran-14 -S -O3 -ffast-math -fopenmp-simd -mavx2 t3.f90
does not vectorise.
$ grep -c ymm t3.s
0
If the extra brackets are removed, so that the loop line reads
a(i)=a(i)+(6d0,1d0)
then it does.
$ grep -c ymm t3.s
3
It seems surprising that the code produced should differ depending on whether
the brackets are present, as I do not believe that they alter the meaning of
the code in any way. One can construct many similar examples, e.g. using a
complex variable in the place of the (6d0,1d0), or using a real constant, etc.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/115563] Unnecessary brackets prevent fortran vectorisation
2024-06-20 17:56 [Bug fortran/115563] New: Unnecessary brackets prevent fortran vectorisation mjr19 at cam dot ac.uk
@ 2024-06-20 18:01 ` pinskia at gcc dot gnu.org
2024-06-20 18:03 ` pinskia at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-20 18:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115563
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |pinskia at gcc dot gnu.org
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
_11 = ((_9));
_19 = REALPART_EXPR <_11>;
_20 = IMAGPART_EXPR <_11>;
REALPART_EXPR <(*a_7(D))[_6]> = _19;
IMAGPART_EXPR <(*a_7(D))[_6]> = _20;
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/115563] Unnecessary brackets prevent fortran vectorisation
2024-06-20 17:56 [Bug fortran/115563] New: Unnecessary brackets prevent fortran vectorisation mjr19 at cam dot ac.uk
2024-06-20 18:01 ` [Bug fortran/115563] " pinskia at gcc dot gnu.org
@ 2024-06-20 18:03 ` pinskia at gcc dot gnu.org
2024-06-20 18:04 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-20 18:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115563
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |DUPLICATE
Status|UNCONFIRMED |RESOLVED
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup.
*** This bug has been marked as a duplicate of bug 68855 ***
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/115563] Unnecessary brackets prevent fortran vectorisation
2024-06-20 17:56 [Bug fortran/115563] New: Unnecessary brackets prevent fortran vectorisation mjr19 at cam dot ac.uk
2024-06-20 18:01 ` [Bug fortran/115563] " pinskia at gcc dot gnu.org
2024-06-20 18:03 ` pinskia at gcc dot gnu.org
@ 2024-06-20 18:04 ` pinskia at gcc dot gnu.org
2024-06-20 23:49 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-20 18:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115563
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note the full IR:
_9 = COMPLEX_EXPR <_15, _14>;
_11 = ((_9));
_19 = REALPART_EXPR <_11>;
_20 = IMAGPART_EXPR <_11>;
REALPART_EXPR <(*a_7(D))[_6]> = _19;
IMAGPART_EXPR <(*a_7(D))[_6]> = _20;
Yes it is a dup.
// (()) is PAREN_EXPR .
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/115563] Unnecessary brackets prevent fortran vectorisation
2024-06-20 17:56 [Bug fortran/115563] New: Unnecessary brackets prevent fortran vectorisation mjr19 at cam dot ac.uk
` (2 preceding siblings ...)
2024-06-20 18:04 ` pinskia at gcc dot gnu.org
@ 2024-06-20 23:49 ` pinskia at gcc dot gnu.org
2024-06-21 8:58 ` mjr19 at cam dot ac.uk
2024-06-24 16:48 ` mjr19 at cam dot ac.uk
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-20 23:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115563
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note I have a fix for this which I attached to PR 68855 and will be submitting
it after the bootstrap/test finishes. Thanks again for the testcase and the
decent bug report. It definitely was useful.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/115563] Unnecessary brackets prevent fortran vectorisation
2024-06-20 17:56 [Bug fortran/115563] New: Unnecessary brackets prevent fortran vectorisation mjr19 at cam dot ac.uk
` (3 preceding siblings ...)
2024-06-20 23:49 ` pinskia at gcc dot gnu.org
@ 2024-06-21 8:58 ` mjr19 at cam dot ac.uk
2024-06-24 16:48 ` mjr19 at cam dot ac.uk
5 siblings, 0 replies; 7+ messages in thread
From: mjr19 at cam dot ac.uk @ 2024-06-21 8:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115563
--- Comment #5 from mjr19 at cam dot ac.uk ---
I'm glad this was useful, and thanks for the impressively rapid fix. I stumbled
across this by chance whilst trying to construct a minimal example for a rather
different missed vectorisation case.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug fortran/115563] Unnecessary brackets prevent fortran vectorisation
2024-06-20 17:56 [Bug fortran/115563] New: Unnecessary brackets prevent fortran vectorisation mjr19 at cam dot ac.uk
` (4 preceding siblings ...)
2024-06-21 8:58 ` mjr19 at cam dot ac.uk
@ 2024-06-24 16:48 ` mjr19 at cam dot ac.uk
5 siblings, 0 replies; 7+ messages in thread
From: mjr19 at cam dot ac.uk @ 2024-06-24 16:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115563
--- Comment #6 from mjr19 at cam dot ac.uk ---
A further comment to aid others reading this report. It is not just unnecessary
brackets which used to prevent vectorisation, but also necessary ones.
subroutine foo(a,b,c,n)
complex (kind(1d0)) :: a(*),b,c
integer :: i,n
do i=1,n
a(i)=(a(i)+b)*c
enddo
end subroutine foo
does not vectorise with gfortran-14, but does with gfortran-15.0-20240623.
The performance increase in loops making extensive use of complex variables can
therefore be quite significant -- fifty percent or more.
The almost-equivalent C code of
void foo(_Complex double *a, _Complex double b, _Complex double c, int n){
int i;
for(i=0;i<n;i++) a[i]=(a[i]+b)*c;
}
does vectorise with gcc-14 (and earlier versions).
I still find gfortran to be slower than ifort for code using complex variables,
as ifort is better at flipping alternate signs in a vector and generally
alternating nops in a vector, see PR 114324 and PR 114767, but this is a very
welcome improvement. Many thanks.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-06-24 16:48 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-20 17:56 [Bug fortran/115563] New: Unnecessary brackets prevent fortran vectorisation mjr19 at cam dot ac.uk
2024-06-20 18:01 ` [Bug fortran/115563] " pinskia at gcc dot gnu.org
2024-06-20 18:03 ` pinskia at gcc dot gnu.org
2024-06-20 18:04 ` pinskia at gcc dot gnu.org
2024-06-20 23:49 ` pinskia at gcc dot gnu.org
2024-06-21 8:58 ` mjr19 at cam dot ac.uk
2024-06-24 16:48 ` mjr19 at cam dot ac.uk
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).