From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1A56B3858428; Fri, 3 Dec 2021 15:16:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1A56B3858428 From: "hubicka at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/103541] New: unnecessary spills around const functions calls Date: Fri, 03 Dec 2021 15:16:13 +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: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: hubicka at gcc dot gnu.org 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: Fri, 03 Dec 2021 15:16:14 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103541 Bug ID: 103541 Summary: unnecessary spills around const functions calls Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: hubicka at gcc dot gnu.org Target Milestone: --- While looking into reasons why modref causes some code size increases I not= iced that we produce unnecessary spill on x86-64 here: float a; __attribute__((const)) float foo (float); float test() { return a + foo(a) + a; } we load "a" into register and then spill it to stack because all SSE regist= ers are clobbered by the call. This seems to happen somewhere between gcc 4.1 a= nd 4.6. It is caused by: /* We can combine a reg def from one insn into a reg use in another over a call if the memory is readonly or the call const/pure. However, we can't set reg_equiv notes up for reload over any call. The problem is the equivalent form may reference a pseudo which gets assigned a call clobbered hard reg. When we later replace REG with its equivalent form, the value in the call-clobbered reg has been changed and all hell breaks loose. */ ret =3D valid_combine; if (!MEM_READONLY_P (memref) && !RTL_CONST_OR_PURE_CALL_P (insn)) return valid_none; in ira.c:validate_equiv_mem If I read the comment correctly it is afraid of the address of memory readi= ng being altered by the call (using call clobbered registers). But here it is a constant, so perhaps we can just rule this out when MEM rtx does not mention registers or does not mention any callee clobbered registers?=