public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "dwwork at gmail dot com" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-102510-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102510 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 this 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 produce 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 understanding. subroutine add2vecs1(a,b,c) use iso_fortran_env, only: r32 => real32 real(r32), dimension(8), intent(in) :: a,b real(r32), dimension(8), intent(out) :: c c = 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 => real32 real(r32), dimension(8), intent(in) :: a,b real(r32), dimension(8) :: add2vecs2 add2vecs2 = 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
next reply other threads:[~2021-09-28 2:17 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-09-28 2:17 dwwork at gmail dot com [this message] 2021-09-28 8:54 ` [Bug fortran/102510] Function call has unnecessary stride check rguenth at gcc dot gnu.org 2021-09-28 13:55 ` dwwork at gmail dot com 2021-09-28 19:03 ` anlauf at gcc dot gnu.org 2021-09-28 19:26 ` dwwork at gmail dot com 2021-09-29 21:01 ` anlauf at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-102510-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).