From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 97E1D3860002; Thu, 18 Jan 2024 12:56:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 97E1D3860002 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1705582589; bh=6TpA9aqG62MCpCibEeas+w1lnKtgcInZVWU+TP4dAmM=; h=From:To:Subject:Date:From; b=Sv5pmqc5gCxZXWWrexBmyyTE+X13ig+MLPvGhDEjAnEg9wFNvOuutRSdJPRfO7+E3 ZSg4MWkVYvDIS5OJa1XfjkmOg5a75+Lum+iO0piHpkv8EwFQE1cV0THKoezxEvH+nB 8I1cO9qtwvhlt/GLR6JkfHJrnp/TNW84E8k6AmZI= From: "jari.helaakoski at qt dot io" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/113478] New: -Os does not inline single instruction function Date: Thu, 18 Jan 2024 12:56:28 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 13.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jari.helaakoski at qt dot io 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=3D113478 Bug ID: 113478 Summary: -Os does not inline single instruction function Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: jari.helaakoski at qt dot io Target Milestone: --- GCC -Os option does not inline single instruction std::atomic function when accessed via template class. Inlining works ok with -O2. Inlining is also working if std::atomic is used directly.=20 Test case and compilation result found from godbolt: https://godbolt.org/z/nh758aT3K Problem reproduces all GCC versions with x86 and aarch64 target and with and without specific -march and -mtune options. And here's test case pasted in case of godbolt is not accessable: template class D { public: #if 1 inline T test() { return i.load(std::memory_order_relaxed); } #else __attribute__((always_inline)) T test() { return i.load(std::memory_order_relaxed); } #endif std::atomic i {0}; }; D a1; D a2; D a3; D a4; D a5; D a6; extern void mod(); int main() { int ret =3D 0; mod(); ret |=3D a1.test(); ret |=3D a1.test(); ret |=3D a1.test(); ret |=3D a1.test(); ret |=3D a1.test(); ret |=3D a1.test(); ret |=3D a1.test(); ret |=3D a1.test(); ret |=3D a1.test(); ret |=3D a1.test(); ret |=3D a2.test(); ret |=3D a3.test(); ret |=3D a4.test(); ret |=3D a5.test(); ret |=3D a6.test(); return ret; } Function that should be inlined D::test(): ldrb w0, [x0] ret=