public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "bartoldeman at users dot sourceforge.net" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/107294] New: Missed optimization: multiplying real with complex number in Fortran (only) Date: Mon, 17 Oct 2022 12:39:29 +0000 [thread overview] Message-ID: <bug-107294-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107294 Bug ID: 107294 Summary: Missed optimization: multiplying real with complex number in Fortran (only) Product: gcc Version: 11.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: bartoldeman at users dot sourceforge.net Target Milestone: --- This code: complex function csmul(a, b) real, value :: a complex, value :: b csmul = a * b end function csmul produces this assembly on x86-64 (11.3, -O2) 0: 66 0f d6 4c 24 f8 movq %xmm1,-0x8(%rsp) 6: f3 0f 10 64 24 fc movss -0x4(%rsp),%xmm4 c: f3 0f 10 4c 24 f8 movss -0x8(%rsp),%xmm1 12: 0f 28 d0 movaps %xmm0,%xmm2 15: 66 0f ef db pxor %xmm3,%xmm3 # xmm3 = 0 19: f3 0f 59 d1 mulss %xmm1,%xmm2 1d: 0f 28 ec movaps %xmm4,%xmm5 20: f3 0f 59 eb mulss %xmm3,%xmm5 # xmm5 = 0 24: f3 0f 59 c4 mulss %xmm4,%xmm0 28: f3 0f 59 cb mulss %xmm3,%xmm1 # xmm1 = 0 2c: f3 0f 5c d5 subss %xmm5,%xmm2 # xmm2 unchanged 30: f3 0f 58 c1 addss %xmm1,%xmm0 # xmm0 unchanged 34: f3 0f 11 54 24 f0 movss %xmm2,-0x10(%rsp) 3a: f3 0f 11 44 24 f4 movss %xmm0,-0xc(%rsp) 40: f3 0f 7e 44 24 f0 movq -0x10(%rsp),%xmm0 46: c3 retq here xmm3 (imaginary part of a, promoted to complex) is set to 0 but this is not exploited in the remainder. On the other hand the assembly for the corresponding C code looks good, with two mul instructions, as expected: float _Complex csmul(float a, float _Complex b) { return a * b; } 0000000000000000 <csmul>: 0: 66 0f d6 4c 24 f8 movq %xmm1,-0x8(%rsp) 6: f3 0f 10 4c 24 f8 movss -0x8(%rsp),%xmm1 c: f3 0f 59 c8 mulss %xmm0,%xmm1 10: f3 0f 59 44 24 fc mulss -0x4(%rsp),%xmm0 16: f3 0f 11 4c 24 f0 movss %xmm1,-0x10(%rsp) 1c: f3 0f 11 44 24 f4 movss %xmm0,-0xc(%rsp) 22: f3 0f 7e 44 24 f0 movq -0x10(%rsp),%xmm0 28: c3 retq The same issue is still present in trunk, according to godbolt.org.
next reply other threads:[~2022-10-17 12:39 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-10-17 12:39 bartoldeman at users dot sourceforge.net [this message] 2022-10-17 12:58 ` [Bug fortran/107294] " rguenth at gcc dot gnu.org 2022-10-17 13:02 ` rguenth at gcc dot gnu.org 2022-10-17 15:14 ` kargl at gcc dot gnu.org 2022-10-17 16:13 ` bartoldeman at users dot sourceforge.net 2022-10-17 16:14 ` bartoldeman at users dot sourceforge.net 2024-06-17 10:03 ` mjr19 at cam dot ac.uk 2024-06-17 14:38 ` kargls at comcast dot net
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-107294-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).