From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CAB0A3858D28; Mon, 17 Oct 2022 12:39:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CAB0A3858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666010369; bh=ouw71mwRXJI5bapRkiHFEyWlzSBzeEKBXZ/7OJYwFXo=; h=From:To:Subject:Date:From; b=uxOjm4dL3YQtqZcRIJXOMPjDvXFlldODPo9mOXybepzIvg2SI/PX/7ZVB8HPcN3go ZZZ/BnwL05KVqChHPyd5ea7r43yKViXC7BPPS6xnKxRIql3DOggn/C7YDlDXDcZUGo ZWslQRAlVfAyP3UU/CvgJ5cvNiqhn60yJY40yG30= From: "bartoldeman at users dot sourceforge.net" 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 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.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: bartoldeman at users dot sourceforge.net 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107294 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 =3D 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 =3D 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 =3D 0 24: f3 0f 59 c4 mulss %xmm4,%xmm0 28: f3 0f 59 cb mulss %xmm3,%xmm1 # xmm1 =3D 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=20=20=20=20 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 : 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=20=20=20 The same issue is still present in trunk, according to godbolt.org.=