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

            Bug ID: 120468
           Summary: Inlining fails when using -momit-leaf-frame-pointer,
                    optimize attribute, and push_options pragma
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ipa
          Assignee: unassigned at gcc dot gnu.org
          Reporter: abbeyj+gcc at gmail dot com
  Target Milestone: ---

In the source code below, I would expect the call to `foo` to be inlined into
`baz`, but it isn't.  Compile with `g++ -O2 -fno-omit-frame-pointer
-momit-leaf-frame-pointer -c repro.cpp`

```
double g_d;
inline double& foo() { return g_d; }

__attribute__((optimize("-fno-unsafe-math-optimizations")))
void bar() {
}

#pragma GCC push_options
#pragma GCC pop_options

void baz() {
  foo() = 1.0;
}
```

Removing the `optimize attribute or the pair of `pragma`s (or both) leads to
the inlining again happening as expected.


Compiling with `-fdump-ipa-inline` produces the following interesting
information:

```
...
  target_flags (0x58002803/0x58202803)
...
IPA function summary for void baz()/3 inlinable
...
  calls:
    double& foo()/1 target specific option mismatch
      freq:1.00 loop depth: 0 size: 2 time: 11 callee size: 1 stack: 0
...
```

The target_flags values above differ by 0x00200000.  I believe that is
MASK_OMIT_LEAF_FRAME_POINTER.  It looks like the flag for
`-momit-leaf-frame-pointer` has been changed between `foo` and `baz` so now
inlining can no longer happen.

Godbolt link: https://godbolt.org/z/aqq7j4bbr

This works in GCC v14.1 but fails in GCC v14.2 and later.

Reply via email to