public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug ipa/102554] New: [ 10/11/12 Regresion ] Inlining missed at -O3 with non-default --param=early-inlining-insns and pragma optimize
@ 2021-10-01 15:52 jschoen4 at gmail dot com
  2021-10-04  6:53 ` [Bug ipa/102554] [10/11/12 Regression] " rguenth at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: jschoen4 at gmail dot com @ 2021-10-01 15:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102554

            Bug ID: 102554
           Summary: [ 10/11/12 Regresion ] Inlining missed at -O3 with
                    non-default --param=early-inlining-insns and pragma
                    optimize
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ipa
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jschoen4 at gmail dot com
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---

GNU C++14 (GCC) version 10.2.0 (x86_64-pc-linux-gnu)
        compiled by GNU C version 10.2.0, GMP version 6.0.0, MPFR version
3.1.1, MPC version 1.0.1, isl version isl-0.16.1-GMP

Target: x86_64-pc-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.2.0 (GCC)

===========
=TEST CODE=
===========
cat test.cpp
#pragma GCC push_options
#pragma GCC optimize ("no-lifetime-dse")
class TestClass
{
public:
  static inline int should_inline() {
    return 10;
  }
};
#pragma GCC pop_options

int main() {
  return TestClass::should_inline() + 1;
}

===========
=cmd      =
===========
gcc-10 test.cpp -S --param=early-inlining-insns=30 -O3 -fno-lifetime-dse -Wall
-Wextra

===========
=BAD ASM  =
===========
cat test.s
        .file   "test.cpp"
        .text
        .section       
.text._ZN9TestClass13should_inlineEv,"axG",@progbits,_ZN9TestClass13should_inlineEv,comdat
        .p2align 4
        .weak   _ZN9TestClass13should_inlineEv
        .type   _ZN9TestClass13should_inlineEv, @function
_ZN9TestClass13should_inlineEv:
.LFB0:
        .cfi_startproc
        movl    $10, %eax
        ret
        .cfi_endproc
.LFE0:
        .size   _ZN9TestClass13should_inlineEv,
.-_ZN9TestClass13should_inlineEv
        .section        .text.startup,"ax",@progbits
        .p2align 4
        .globl  main
        .type   main, @function
main:
.LFB1:
        .cfi_startproc
        subq    $8, %rsp
        .cfi_def_cfa_offset 16
        call    _ZN9TestClass13should_inlineEv
        addq    $8, %rsp
        .cfi_def_cfa_offset 8
        addl    $1, %eax
        ret
        .cfi_endproc
.LFE1:
        .size   main, .-main
        .ident  "GCC: (GNU) 10.2.0"
        .section        .note.GNU-stack,"",@progbits

===========
=info     =
===========
cat test.cpp.079i.inline
...
Deciding on inlining of small functions.  Starting with size 9.
Enqueueing calls in int main()/1.
test.cpp:13:34: missed:   not inlinable: int main()/1 -> static int
TestClass::should_inline()/0, optimization level attribute mismatch

  param_early_inlining_insns (0x1e/0xe)
Enqueueing calls in static int TestClass::should_inline()/0.
node context cache: 0 hits, 0 misses, 1 initializations
...

===========
=GOOD ASM =
===========
gcc-10 test.cpp -S --param=early-inlining-insns=14 -O3 -fno-lifetime-dse -Wall
-Wextra
        .file   "test.cpp"
        .text
        .section        .text.startup,"ax",@progbits
        .p2align 4
        .globl  main
        .type   main, @function
main:
.LFB1:
        .cfi_startproc
        movl    $11, %eax
        ret
        .cfi_endproc
.LFE1:
        .size   main, .-main
        .ident  "GCC: (GNU) 10.2.0"
        .section        .note.GNU-stack,"",@progbits


==========
=notes=
==========

Starting with gcc 10+ (gcc9 works correctly), the use of
--param=early-inlining-insns=30 and -O3 on the command line combined with using
a "#pragma GCC optimize" in source code, even one that does not change the
effective optimization attributes, causes "optimization level attribute
mismatch" to occur in the inliner.

In the example I placed both -fno-lifetime-dse on the command line and in the
pragma gcc optimize ("no-lifetime-dse"),  so it has no impact at all to the
effective optimization attributes.  

The issue is not specific to using just pragma GCC optimize "no-lifetime-dse",
any pragma gcc optimize line will have this effect. Even "unrecognized" ones. 
i.e.
#pragma GCC optimize ("fake_attribute")

Any value OTHER THAN --param=early-inlining-insns=14 on the command line when
used with -O3 and pragma optimize will trigger this.
.. i.e.
======================
=optimize correctly  =
======================
gcc-10 test.cpp -S --param=early-inlining-insns=14 -O3 -fno-lifetime-dse -Wall
-Wextra

gcc-10 test.cpp -S --param=early-inlining-insns=30 -O2 -fno-lifetime-dse -Wall
-Wextra

gcc-9 test.cpp -S --param=early-inlining-insns=30 -O3 -fno-lifetime-dse -Wall
-Wextra

======================
=missed optimize     =
======================
gcc-10 test.cpp -S --param=early-inlining-insns=12 -O3 -fno-lifetime-dse -Wall
-Wextra

gcc-10 test.cpp -S --param=early-inlining-insns=17 -O3 -fno-lifetime-dse -Wall
-Wextra
etc.

gcc-11 test.cpp -S --param=early-inlining-insns=30 -O3 -fno-lifetime-dse -Wall
-Wextra
gcc-12 test.cpp -S --param=early-inlining-insns=30 -O3 -fno-lifetime-dse -Wall
-Wextra
gcc-trunk test.cpp -S --param=early-inlining-insns=30 -O3 -fno-lifetime-dse
-Wall -Wextra


Code path where CIF_OPTIMIZATION_MISMATCH is being set.

gcc/ipa-inline.c:
    568 can_early_inline_edge_p (struct cgraph_edge *e)
...
    593   if (!can_inline_edge_p (e, true, true)
    594       || !can_inline_edge_by_limits_p (e, true, false, true))

-------->

    428 can_inline_edge_by_limits_p (struct cgraph_edge *e, bool report,
    429                              bool disregard_limits = false, bool early
= false)
...
    524       /* When user added an attribute to the callee honor it.  */
    525       else if (lookup_attribute ("optimize", DECL_ATTRIBUTES
(callee->decl))
    526                && opts_for_fn (caller->decl) != opts_for_fn
(callee->decl))
    527         {
    528           e->inline_failed = CIF_OPTIMIZATION_MISMATCH;
    529           inlinable = false;
    530         }


I suspect the change that moved the --params= options into the cl_optimization
struct is related to this misssed optimization.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-07-07 10:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-01 15:52 [Bug ipa/102554] New: [ 10/11/12 Regresion ] Inlining missed at -O3 with non-default --param=early-inlining-insns and pragma optimize jschoen4 at gmail dot com
2021-10-04  6:53 ` [Bug ipa/102554] [10/11/12 Regression] " rguenth at gcc dot gnu.org
2021-10-04  7:09 ` [Bug ipa/102554] [10/11 " marxin at gcc dot gnu.org
2021-10-04 14:05 ` jschoen4 at gmail dot com
2021-10-04 15:09 ` marxin at gcc dot gnu.org
2022-06-28 10:46 ` jakub at gcc dot gnu.org
2023-07-07 10:41 ` [Bug ipa/102554] [11 " rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).