From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BC1AB385801A; Fri, 18 Feb 2022 13:52:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BC1AB385801A From: "m.cencora at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/104597] LTO does not inline indirect call Date: Fri, 18 Feb 2022 13:52:33 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 11.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: m.cencora 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: Message-ID: In-Reply-To: References: 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, 18 Feb 2022 13:52:33 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104597 --- Comment #2 from m.cencora at gmail dot com --- Similarly when indirect call is a result of virtual function call, gcc cann= ot optimize it, while clang can: // main.cpp struct foo { virtual int getInt0() const =3D 0; virtual int getInt1() const =3D 0; }; const foo& getFooInstance(); namespace { int test() { auto& foo =3D getFooInstance(); return foo.getInt1(); } } int main() { return test(); } // lib1.cpp struct foo { virtual int getInt0() const =3D 0; virtual int getInt1() const =3D 0; }; namespace { struct bar final : foo { int getInt0() const override { return 0; } int getInt1() const override { return 1; } }; constexpr bar b; } const foo& getFooInstance() { return b; } gcc-11 output: Dump of assembler code for function main: 0x0000000000001040 <+0>: endbr64=20 0x0000000000001044 <+4>: lea 0x2d75(%rip),%rdi # 0x3dc0 <_ZN12_GLOBAL__N_1L1bE> 0x000000000000104b <+11>: jmp 0x1150 <_ZNK12_GLOBAL__N_13bar7getInt1Ev> clang-12 output: Dump of assembler code for function main: 0x0000000000401110 <+0>: mov $0x1,%eax 0x0000000000401115 <+5>: ret=