public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/59883] New: Missed C++ front-end devirtualizations
@ 2014-01-19 19:09 hubicka at gcc dot gnu.org
  2014-01-29 20:41 ` [Bug c++/59883] " hubicka at gcc dot gnu.org
  2023-08-04 21:42 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: hubicka at gcc dot gnu.org @ 2014-01-19 19:09 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59883

            Bug ID: 59883
           Summary: Missed C++ front-end devirtualizations
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hubicka at gcc dot gnu.org

I believe the following testcase:
     struct A 
    {
       virtual int foo (void) {return foo();}
    }; 

    struct B {
       struct A a;
    };
    struct A a[7]; 

    int test(void)
    {
      return a[3].foo();
    } 

    int test2(struct B *b)
    {
      return b->a.foo();
    }
ought to get devirtualized by C++ FE based on the fact that the object is
contained within an structure or array. (this is related to PR46507)

In the following testcase:
namespace {
  struct A 
  {
    virtual int foo (void) {return 42;}
  };
}
int test(void)
{
  struct A a, *b=&a;
  return b->foo();
}

We can now probably use ipa-devirt's type inheritance graph to work out right
away that A is a final class.

And finally:
struct A 
{
   virtual int foo (void) {return foo();}
};
IMO allows devirtualization of self recursive functions


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

* [Bug c++/59883] Missed C++ front-end devirtualizations
  2014-01-19 19:09 [Bug c++/59883] New: Missed C++ front-end devirtualizations hubicka at gcc dot gnu.org
@ 2014-01-29 20:41 ` hubicka at gcc dot gnu.org
  2023-08-04 21:42 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: hubicka at gcc dot gnu.org @ 2014-01-29 20:41 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59883

--- Comment #1 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
The self-recursion testcase is wrong, as can be seen by the following testcase:

#include <stdio.h>
struct A
{
   virtual int foo (void) {return foo()+1;}
};
struct B: public A
{
   virtual int foo (void) {return 1;}
};
main()
{
  struct B b;
  printf("%i\n",b.A::foo());
}

Still, given that recursive virtual functions seems frequent, I wonder if we
can't
try to track such explicit calls that breaks the assumption that a virtual
function is called only for derived types that do not overwrite it and try to
optimize at least for local functions...


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

* [Bug c++/59883] Missed C++ front-end devirtualizations
  2014-01-19 19:09 [Bug c++/59883] New: Missed C++ front-end devirtualizations hubicka at gcc dot gnu.org
  2014-01-29 20:41 ` [Bug c++/59883] " hubicka at gcc dot gnu.org
@ 2023-08-04 21:42 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-04 21:42 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=110057

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The first example with arrays is PR 110057 also.

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

end of thread, other threads:[~2023-08-04 21:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-19 19:09 [Bug c++/59883] New: Missed C++ front-end devirtualizations hubicka at gcc dot gnu.org
2014-01-29 20:41 ` [Bug c++/59883] " hubicka at gcc dot gnu.org
2023-08-04 21:42 ` 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).