public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug ipa/114703] New: Missed devirtualization in rather simple case
@ 2024-04-12 13:57 konstantin.vladimirov at gmail dot com
  2024-04-12 22:01 ` [Bug ipa/114703] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: konstantin.vladimirov at gmail dot com @ 2024-04-12 13:57 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114703
           Summary: Missed devirtualization in rather simple case
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ipa
          Assignee: unassigned at gcc dot gnu.org
          Reporter: konstantin.vladimirov at gmail dot com
  Target Milestone: ---

See code here:

https://godbolt.org/z/T9Ma7qe3E

struct A {
  virtual int foo() { return 1; }
};

struct B : A {
  int foo() override { return 2; }
  virtual int foo(int i) { return i + 1; }
};

int use(int, int, int);

int main() {
  B *p = new B;
#if 0
  A* q = p;
#else
  A* q = new B;
#endif  
  int result1 = p->foo(1);
  int result2 = p->foo();
  int result3 = q->foo();
  use(result1, result2, result3);
}

clang devirtualizes just fine, gcc lacks this one.

Interesting that if you flip preprocessor switch, everything works with gcc
either.

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

* [Bug ipa/114703] Missed devirtualization in rather simple case
  2024-04-12 13:57 [Bug ipa/114703] New: Missed devirtualization in rather simple case konstantin.vladimirov at gmail dot com
@ 2024-04-12 22:01 ` pinskia at gcc dot gnu.org
  2024-04-12 22:11 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-12 22:01 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-04-12
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The problem I think is we don't realize that `operator new` can't touch the
other memory that was just allocated partly because the escape analysis is not
flow sensitive .

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

* [Bug ipa/114703] Missed devirtualization in rather simple case
  2024-04-12 13:57 [Bug ipa/114703] New: Missed devirtualization in rather simple case konstantin.vladimirov at gmail dot com
  2024-04-12 22:01 ` [Bug ipa/114703] " pinskia at gcc dot gnu.org
@ 2024-04-12 22:11 ` pinskia at gcc dot gnu.org
  2024-04-15  7:53 ` rguenth at gcc dot gnu.org
  2024-04-15 10:20 ` hubicka at ucw dot cz
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-12 22:11 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

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

* [Bug ipa/114703] Missed devirtualization in rather simple case
  2024-04-12 13:57 [Bug ipa/114703] New: Missed devirtualization in rather simple case konstantin.vladimirov at gmail dot com
  2024-04-12 22:01 ` [Bug ipa/114703] " pinskia at gcc dot gnu.org
  2024-04-12 22:11 ` pinskia at gcc dot gnu.org
@ 2024-04-15  7:53 ` rguenth at gcc dot gnu.org
  2024-04-15 10:20 ` hubicka at ucw dot cz
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-04-15  7:53 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hubicka at gcc dot gnu.org

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Yep, 'new' memory escapes.

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

* [Bug ipa/114703] Missed devirtualization in rather simple case
  2024-04-12 13:57 [Bug ipa/114703] New: Missed devirtualization in rather simple case konstantin.vladimirov at gmail dot com
                   ` (2 preceding siblings ...)
  2024-04-15  7:53 ` rguenth at gcc dot gnu.org
@ 2024-04-15 10:20 ` hubicka at ucw dot cz
  3 siblings, 0 replies; 5+ messages in thread
From: hubicka at ucw dot cz @ 2024-04-15 10:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jan Hubicka <hubicka at ucw dot cz> ---
> Yep, 'new' memory escapes.
Yep, this is blocking a lot of propagation in common C++ code.
Here it may help to do speculative devirtualization during IPA stage
that will let the late optimization to get rid of the speculation (since
after inlning we will know that the virtual call does not overwrite
virtual table pointer).  This is technically not too hard to add.  We
can optimistically rule out (some) may aliases while walking the alias
oracle.   I will take a look next stage1.

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

end of thread, other threads:[~2024-04-15 10:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-12 13:57 [Bug ipa/114703] New: Missed devirtualization in rather simple case konstantin.vladimirov at gmail dot com
2024-04-12 22:01 ` [Bug ipa/114703] " pinskia at gcc dot gnu.org
2024-04-12 22:11 ` pinskia at gcc dot gnu.org
2024-04-15  7:53 ` rguenth at gcc dot gnu.org
2024-04-15 10:20 ` hubicka at ucw dot cz

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).