https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107254
Bug ID: 107254 Summary: Wrong vectorizer code (GCC 11 only, Fortran) Product: gcc Version: 11.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: bartoldeman at users dot sourceforge.net Target Milestone: --- Created attachment 53703 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53703&action=edit Test case The following code gives the wrong result (-1.0000000000000000 instead of 0.0000000000000000) with gfortran 11.3 (also tested with the 11.3.1 20221007 prerelease) when given the options `-O2 -ftree-vectorize -march=core-avx` for x86_64. There's no issue with GCC 9,10, and 12. It could be related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107212 except that bug also affects GCC 12. This issue came up from testing the reference LAPACK with -ftree-vectorize enabled, where many more tests failed with recent GCC (11/12), see https://github.com/easybuilders/easybuild-easyconfigs/issues/16380 $ gfortran -O2 -ftree-vectorize -march=core-avx2 dhgeqz2.f90; ./a.out -1.0000000000000000 $ gfortran -Wall -O2 dhgeqz2.f90; ./a.out 0.0000000000000000 subroutine dlartg( f, g, s, r ) implicit none double precision :: f, g, r, s double precision :: d, p d = sqrt( f*f + g*g ) p = 1.d0 / d if( abs( f ) > 1 ) then s = g*sign( p, f ) r = sign( d, f ) else s = g*sign( p, f ) r = sign( d, f ) end if end subroutine subroutine dhgeqz( n, h, t ) implicit none integer n double precision h( n, * ), t( n, * ) integer jc double precision c, s, temp, temp2, tempr temp2 = 10d0 call dlartg( 10d0, temp2, s, tempr ) c = 0.9d0 s = 1.d0 do jc = 1, n temp = c*h( 1, jc ) + s*h( 2, jc ) h( 2, jc ) = -s*h( 1, jc ) + c*h( 2, jc ) h( 1, jc ) = temp temp2 = c*t( 1, jc ) + s*t( 2, jc ) ! t(2,2)=-s*t(1,2)+c*t(2,2)=-0.9*0+1*0=0 t( 2, jc ) = -s*t( 1, jc ) + c*t( 2, jc ) t( 1, jc ) = temp2 enddo end subroutine dhgeqz program test implicit none double precision h(2,2), t(2,2) h = 0 t(1,1) = 1 t(2,1) = 0 t(1,2) = 0 t(2,2) = 0 call dhgeqz( 2, h, t ) print *,t(2,2) end program test