[Bug tree-optimization/87205] Inefficient code generation for switch

2018-09-05 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87205 Martin Liška changed: What|Removed |Added Status|ASSIGNED|RESOLVED Resolution|---

[Bug tree-optimization/87205] Inefficient code generation for switch

2018-09-05 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87205 --- Comment #11 from Martin Liška --- Author: marxin Date: Wed Sep 5 11:28:49 2018 New Revision: 264124 URL: https://gcc.gnu.org/viewcvs?rev=264124&root=gcc&view=rev Log: Group switch cases in switch lowering (PR tree-optimization/87205). 2018

[Bug tree-optimization/87205] Inefficient code generation for switch

2018-09-05 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87205 --- Comment #10 from Martin Liška --- (In reply to Peter Dimov from comment #8) > (In reply to Martin Liška from comment #7) > > I'm not sure here Y are different types here and member access based on > > the type is distinct. > > Yes, one could

[Bug tree-optimization/87205] Inefficient code generation for switch

2018-09-04 Thread pdimov at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87205 --- Comment #9 from Peter Dimov --- For more context, see https://godbolt.org/z/SzfpKr ``` #include template struct variant { std::aligned_union_t<0, T...> storage_; unsigned index_; }; template auto visit( variant& v, F f ) { swi

[Bug tree-optimization/87205] Inefficient code generation for switch

2018-09-04 Thread pdimov at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87205 --- Comment #8 from Peter Dimov --- (In reply to Martin Liška from comment #7) > I'm not sure here Y are different types here and member access based on > the type is distinct. Yes, one could argue that, I suppose. But in the `return ((Y<0>*)p)-

[Bug tree-optimization/87205] Inefficient code generation for switch

2018-09-04 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87205 --- Comment #7 from Martin Liška --- (In reply to Peter Dimov from comment #5) > Another: > > ``` > struct X > { > int v; > }; > > template struct Y: X > { > }; > > void f( int v ); > > void h( unsigned ix, void* p ) > { > switch( ix

[Bug tree-optimization/87205] Inefficient code generation for switch

2018-09-04 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87205 --- Comment #6 from Martin Liška --- > ``` > h(unsigned int, void*): > cmp edi, 5 > jbe .L5 > .L5: > mov rdi, rsi > jmp f(X*) > ``` > > https://godbolt.org/z/2Lh_GZ Good, my patch can handle that and can generate direct call: _Z1hjPv:

[Bug tree-optimization/87205] Inefficient code generation for switch

2018-09-04 Thread pdimov at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87205 --- Comment #5 from Peter Dimov --- Another: ``` struct X { int v; }; template struct Y: X { }; void f( int v ); void h( unsigned ix, void* p ) { switch( ix ) { case 0: f( ((Y<0>*)p)->v ); break; case 1: f( ((Y<1>*

[Bug tree-optimization/87205] Inefficient code generation for switch

2018-09-04 Thread pdimov at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87205 --- Comment #4 from Peter Dimov --- If the code is not the same the jump table is not optimized out and there's no extra check. But it also happens with code that is not the same on the C++ side, for example: ``` struct X { int v; }; templa

[Bug tree-optimization/87205] Inefficient code generation for switch

2018-09-04 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87205 Martin Liška changed: What|Removed |Added Target Milestone|--- |9.0