From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D120C3858C2C; Tue, 28 Sep 2021 02:17:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D120C3858C2C From: "dwwork at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/102510] New: Function call has unnecessary aliasing check Date: Tue, 28 Sep 2021 02:17:15 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 11.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: dwwork at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Sep 2021 02:17:15 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102510 Bug ID: 102510 Summary: Function call has unnecessary aliasing check Product: gcc Version: 11.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: dwwork at gmail dot com Target Milestone: --- The following 2 functions semantically do the same thing, they add two fixed size arrays and store them into a third. When compiled with "-O3 -mavx" for x86_64, I expect to see a single avx instruction. The first version does th= is correctly, while the second has an aliasing check with a vectorized branch = and a scalar branch (I think). The second version is incorrect, and should prod= uce similar vectorized assembly to the first, as fortran does not allow function arguments to alias. I could be wrong of course, but that is my understandin= g. subroutine add2vecs1(a,b,c) use iso_fortran_env, only: r32 =3D> real32 real(r32), dimension(8), intent(in) :: a,b real(r32), dimension(8), intent(out) :: c c =3D a + b end subroutine Output Assembly (from godbolt.org, https://godbolt.org/z/aedEe7rGM): add2vecs1_: vmovups ymm0, YMMWORD PTR [rdi] vaddps ymm0, ymm0, YMMWORD PTR [rsi] vmovups YMMWORD PTR [rdx], ymm0 vzeroupper ret function add2vecs2(a,b) use iso_fortran_env, only: r32 =3D> real32 real(r32), dimension(8), intent(in) :: a,b real(r32), dimension(8) :: add2vecs2 add2vecs2 =3D a + b end function Output Assembly: add2vecs2_: mov rax, QWORD PTR [rdi+40] mov rcx, QWORD PTR [rdi] test rax, rax je .L5 cmp rax, 1 jne .L11 .L5: vmovups ymm0, YMMWORD PTR [rdx] vaddps ymm0, ymm0, YMMWORD PTR [rsi] vmovups YMMWORD PTR [rcx], ymm0 vzeroupper ret .L11: vmovups xmm1, XMMWORD PTR [rdx] vaddps xmm0, xmm1, XMMWORD PTR [rsi] lea rdi, [rcx+rax*8] mov r8, rax sal r8, 4 vmovss DWORD PTR [rcx], xmm0 vextractps DWORD PTR [rcx+rax*4], xmm0, 1 vextractps DWORD PTR [rcx+rax*8], xmm0, 2 vextractps DWORD PTR [rdi+rax*4], xmm0, 3 vmovups xmm0, XMMWORD PTR [rdx+16] vaddps xmm0, xmm0, XMMWORD PTR [rsi+16] lea rdi, [rcx+r8] lea rdx, [rdi+rax*8] vmovss DWORD PTR [rcx+r8], xmm0 vextractps DWORD PTR [rdi+rax*4], xmm0, 1 vextractps DWORD PTR [rdi+rax*8], xmm0, 2 vextractps DWORD PTR [rdx+rax*4], xmm0, 3 ret=