From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A692E3858D39; Tue, 7 Mar 2023 12:57:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A692E3858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678193857; bh=Ud1s3j5Ae3tzs6cZoa5epAtj9/aOgX6jncbjZQT15Q0=; h=From:To:Subject:Date:From; b=A9MIYJPMM9lwGvvtz/YZPH6vlvjc5l3j3A3X+16T+zJ7OwsunX3G4dFd6tTA/Foxw 3wPMSytj514EaaAXEchiMcUnXoxDmtwrLfaR9Gjho1E+R567zBbJENasS0fCT6jXKH fzduf0dqVCdq3um00eUPGAxFb6Ql2jTqRH4kBxOc= From: "ubizjak at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/109052] New: Unnecessary reload with -mfpmath=both Date: Tue, 07 Mar 2023 12:57:37 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: ubizjak 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109052 Bug ID: 109052 Summary: Unnecessary reload with -mfpmath=3Dboth Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: ubizjak at gmail dot com Target Milestone: --- Following testcase: --cut here-- double foo (double a) { double tmp =3D a; asm ("" : "+t" (tmp)); return a * tmp; } --cut here-- compiles with -O2 -mfpmath=3Dboth -msse2 to: foo: movsd %xmm0, -8(%rsp) fldl -8(%rsp) fstpl -8(%rsp) --> movsd -8(%rsp), %xmm1 mulsd %xmm1, %xmm0 ret There is no need to reload from -8(%rsp) to %xmm1, mulsd accepts memory operands. Optimal code would be: foo: movsd %xmm0, -8(%rsp) fldl -8(%rsp) fstpl -8(%rsp) mulsd -8(%rsp), %xmm0 ret Please note that with -mfpmath=3Dsse, expected code is generated. The insns pattern is defined in i386.md: (define_insn "*fop__comm" [(set (match_operand:MODEF 0 "register_operand" "=3Df,x,v") (match_operator:MODEF 3 "binary_fp_operator" [(match_operand:MODEF 1 "nonimmediate_operand" "%0,0,v") (match_operand:MODEF 2 "nonimmediate_operand" "fm,xm,vm")]))] "((SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH) || (TARGET_80387 && X87_ENABLE_ARITH (mode))) && COMMUTATIVE_ARITH_P (operands[3]) && !(MEM_P (operands[1]) && MEM_P (operands[2]))" "* return output_387_binary_op (insn, operands);" [(set (attr "type") (if_then_else (eq_attr "alternative" "1,2") (if_then_else (match_operand:MODEF 3 "mult_operator") (const_string "ssemul") (const_string "sseadd")) (if_then_else (match_operand:MODEF 3 "mult_operator") (const_string "fmul") (const_string "fop")))) (set_attr "isa" "*,noavx,avx") (set_attr "prefix" "orig,orig,vex") (set_attr "mode" "") (set (attr "enabled") (if_then_else (match_test ("SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH")) (if_then_else (eq_attr "alternative" "0") (symbol_ref "TARGET_MIX_SSE_I387 && X87_ENABLE_ARITH (mode)") (const_string "*")) (if_then_else (eq_attr "alternative" "0") (symbol_ref "true") (symbol_ref "false"))))]) The difference between -mfpmath=3Dboth and -mfpmath=3Dsse is in alternative= 0, which is enabled with -mfpmath=3Dboth and disabled with -mpmath=3Dsse. Usin= g -mavx instead of -msse2 with -mfpmath=3Dboth does not solve the problem.=