public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/94818] New: GCC emits dead bodies of functions whose all calls have been eliminated by optimisations
@ 2020-04-28 12:43 felix.von.s at posteo dot de
  2020-04-28 13:36 ` [Bug ipa/94818] " rguenth at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: felix.von.s at posteo dot de @ 2020-04-28 12:43 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94818
           Summary: GCC emits dead bodies of functions whose all calls
                    have been eliminated by optimisations
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: felix.von.s at posteo dot de
  Target Milestone: ---
            Target: x86_64-linux-gnu

In this code:

    __attribute__((__warning__("argh")))
    static void foo(void) {
        __asm__ (
            ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"
            ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"
        );
    }

    void bar0(int x) {
        if (__builtin_constant_p(x))
            foo();
    }

    void bar1(int x) {
        if (__builtin_constant_p(x))
            foo();
    }

No calls to foo are emitted in the final output, and GCC knows this, since no
warnings are emitted. However, GCC will still emit a function body for foo,
unless either the __asm__ statement is removed or both conditions are changed
to integer constant expressions, so that the function is eliminated by one of
the inlining passes.

(I decided to demonstrate it this way instead of using
__attribute__((__noinline__)), just to make sure this is not related to
__attribute__((__noinline__)) somehow implying __attribute__((__used__)).)

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

* [Bug ipa/94818] GCC emits dead bodies of functions whose all calls have been eliminated by optimisations
  2020-04-28 12:43 [Bug tree-optimization/94818] New: GCC emits dead bodies of functions whose all calls have been eliminated by optimisations felix.von.s at posteo dot de
@ 2020-04-28 13:36 ` rguenth at gcc dot gnu.org
  2020-04-29  6:27 ` pinskia at gcc dot gnu.org
  2021-07-20 22:23 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-04-28 13:36 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2020-04-28
                 CC|                            |marxin at gcc dot gnu.org
          Component|tree-optimization           |ipa
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.  ___builtin_constant_p is only resolved after IPA optimization and
at that point unreachable functions can no longer be removed reliably
(foo is output before bar0 __builtin_constant_p is resolved).

We could add another "IPA" sync point before RTL expansion but not sure if
we really want to.

We could also see there's no callers to bar0 and bar1 and resolve
__builtin_constant_p earlier during IPA.

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

* [Bug ipa/94818] GCC emits dead bodies of functions whose all calls have been eliminated by optimisations
  2020-04-28 12:43 [Bug tree-optimization/94818] New: GCC emits dead bodies of functions whose all calls have been eliminated by optimisations felix.von.s at posteo dot de
  2020-04-28 13:36 ` [Bug ipa/94818] " rguenth at gcc dot gnu.org
@ 2020-04-29  6:27 ` pinskia at gcc dot gnu.org
  2021-07-20 22:23 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-04-29  6:27 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |47205, 89139

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Related to PR 47205, PR 89139


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47205
[Bug 47205] GCC emits optimized out noinline function
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89139
[Bug 89139] GCC emits code for static functions that aren't used by the
optimized code

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

* [Bug ipa/94818] GCC emits dead bodies of functions whose all calls have been eliminated by optimisations
  2020-04-28 12:43 [Bug tree-optimization/94818] New: GCC emits dead bodies of functions whose all calls have been eliminated by optimisations felix.von.s at posteo dot de
  2020-04-28 13:36 ` [Bug ipa/94818] " rguenth at gcc dot gnu.org
  2020-04-29  6:27 ` pinskia at gcc dot gnu.org
@ 2021-07-20 22:23 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-20 22:23 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement

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

end of thread, other threads:[~2021-07-20 22:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-28 12:43 [Bug tree-optimization/94818] New: GCC emits dead bodies of functions whose all calls have been eliminated by optimisations felix.von.s at posteo dot de
2020-04-28 13:36 ` [Bug ipa/94818] " rguenth at gcc dot gnu.org
2020-04-29  6:27 ` pinskia at gcc dot gnu.org
2021-07-20 22:23 ` pinskia 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).