[Bug tree-optimization/89491] Inline jump tables
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89491 Andrew Pinski changed: What|Removed |Added Last reconfirmed||2021-07-19 Status|UNCONFIRMED |NEW Ever confirmed|0 |1 Severity|normal |enhancement Keywords||missed-optimization --- Comment #6 from Andrew Pinski --- The big question is how useful is this in real code? ICC does it, then there must have been a benchmark where this improves but I don't know which one. Also it looks like ICC does: int f(int x) { const p *t = arr[x]; if (t == square) return square(1); else return add(1); }
[Bug tree-optimization/89491] Inline jump tables
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89491 --- Comment #5 from Dávid Bolvanský --- Let's take the original example with small modification: int square(int x) { return x*x; } int add(int x) { return x + x; } typedef int (*p)(int); static const p arr[4] = {square, add}; int test(int x) { int res = arr[x](1); return res; } Nothing is expanded/inlined. ICC can do it for "two items in arr" case.
[Bug tree-optimization/89491] Inline jump tables
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89491 Jakub Jelinek changed: What|Removed |Added CC||jakub at gcc dot gnu.org --- Comment #4 from Jakub Jelinek --- "Inlining" from vtables is called devirtualization, and GCC performs that either if there is just a single possibility, or with PGO if a particular method is known to be very common. Doing it in other cases is probably not a very good idea.
[Bug tree-optimization/89491] Inline jump tables
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89491 --- Comment #3 from Andrew Pinski --- (In reply to Dávid Bolvanský from comment #2) > Right, static helps. > > What about more complex examples, like inlining vtables? > https://gcc.godbolt.org/z/ZXkRYa Your example is much more complex. The vtable might be constant but where the vtable is stored is not.
[Bug tree-optimization/89491] Inline jump tables
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89491 --- Comment #2 from Dávid Bolvanský --- Right, static helps. What about more complex examples, like inlining vtables? https://gcc.godbolt.org/z/ZXkRYa
[Bug tree-optimization/89491] Inline jump tables
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89491 --- Comment #1 from Andrew Pinski --- arr is non-constant so GCC cannot assume it would be square or add all the time.