From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 42A973849ADC; Fri, 19 Apr 2024 20:05:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 42A973849ADC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1713557150; bh=tOajYHxWG8aD0tZGHBPSv80+zjsvawWnUmL7CL0J1eo=; h=From:To:Subject:Date:From; b=N2YdxBMzp9uy76YSkHC4iWo0YtWQPYvcKWZ6Je4JLpB88258fk4yckvgM2HaOkqLb j1l4FhAUmtczEJ85th40Pq+GHcTZggCbOZ/kCU3ImLEmN1lmqJ0yEbVhb2eG80JT+i Hwuh3oEojdWzBvAJ/yAkU7EW8YiuCeiHMZje5F3o= From: "dani at danielbertalan dot dev" To: gcc-bugs@gcc.gnu.org Subject: [Bug ipa/114784] New: [14 Regression] Inlining fails for always_inline inheriting constructor Date: Fri, 19 Apr 2024 20:05:49 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: ipa X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: dani at danielbertalan dot dev 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=3D114784 Bug ID: 114784 Summary: [14 Regression] Inlining fails for always_inline inheriting constructor Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: ipa Assignee: unassigned at gcc dot gnu.org Reporter: dani at danielbertalan dot dev Target Milestone: --- The code below has been reduced from SerenityOS's custom std::variant-like type. Its constructors are implemented by recursively inheriting from a hel= per class which adds a constructor that can take one of the stored types. This, however, creates a bunch of small constructors - each of which just end up calling into the set() method - which don't necessarily get inlined. Our measurements showed that we can achieve up to 20% reduction in the run time= of our test suite by marking these as __attribute__((always_inline)). (Like in most other similar issues, inlining is not a matter of correctness for us, = we just want to overrule inlining heuristics). Ever since the GCC trunk of summer 2023, we have been getting compile errors about failing to inline these constructors ("call is unlikely and code size would grow"). Below is the smallest reproducer we could create for this iss= ue (admittedly, it has UB, so not sure if it's the exact same issue as in the = real code). Note that if we explicitly write out the constructor instead of inheriting it (even if it does the same thing), as shown by the long long overloads below, the issue goes away (compile with -std=3Dc++20 -O2). See: https://godbolt.org/z/5hb584T9r --- template struct VariantConstructors { __attribute__((always_inline)) VariantConstructors(int t) { base().set(t, {}); } __attribute__((always_inline)) VariantConstructors(long long t) { base().set(t, {}); } Base base(); }; struct Variant : VariantConstructors { using VariantConstructors::VariantConstructors; __attribute__((always_inline)) Variant(long long v) : VariantConstructors= (v) {} template void set(T &&, int); char m_data; }; struct ErrorOr { ErrorOr(int v) : a(v) { } ErrorOr(long long v) : a(v) { } Variant a; }; static ErrorOr run() { ErrorOr x(0); // compiles with this line removed ErrorOr y(0LL); return 0; } int serenity_main() { run(); } --- gcc -v output: GNU C++20 (Compiler-Explorer-Build-gcc-85c187b2127b937e211dfe46b4120d320ff661df-binut= ils-2.40) version 14.0.1 20240419 (experimental) (x86_64-linux-gnu) compiled by GNU C version 11.4.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version isl-0.24-GMP=