public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug tree-optimization/103072] New: Folding common switch code @ 2021-11-04 0:01 llvm at rifkin dot dev 2021-11-04 8:15 ` [Bug tree-optimization/103072] " jakub at gcc dot gnu.org ` (4 more replies) 0 siblings, 5 replies; 6+ messages in thread From: llvm at rifkin dot dev @ 2021-11-04 0:01 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103072 Bug ID: 103072 Summary: Folding common switch code Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: llvm at rifkin dot dev Target Milestone: --- In the following code, GCC can optimize foo but not bar: void foo(int x) { switch(x) { case 1: func1(); break; case 2: func1(); break; case 3: func1(); break; case 4: func1(); break; case 5: func1(); break; default: __builtin_unreachable(); } } void bar(int x) { switch(x) { case 1: func2(x); break; case 2: func2(x); break; case 3: func2(x); break; case 4: func2(x); break; case 5: func2(x); break; default: __builtin_unreachable(); } } https://godbolt.org/z/3eqnG71f5 (LLVM optimizes both) ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/103072] Folding common switch code 2021-11-04 0:01 [Bug tree-optimization/103072] New: Folding common switch code llvm at rifkin dot dev @ 2021-11-04 8:15 ` jakub at gcc dot gnu.org 2021-11-04 9:12 ` rguenth at gcc dot gnu.org ` (3 subsequent siblings) 4 siblings, 0 replies; 6+ messages in thread From: jakub at gcc dot gnu.org @ 2021-11-04 8:15 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103072 Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org, | |marxin at gcc dot gnu.org --- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> --- We optimize the second function to: void baz(int x) { switch(x) { case 1: func2(1); break; case 2: func2(2); break; case 3: func2(3); break; case 4: func2(4); break; case 5: func2(5); break; default: __builtin_unreachable(); } } during evrp and cross-jumping isn't able to merge it then. Users could very well write it the above way too. So maybe the switchconv pass could be improved not to do just the linear etc. expression handling, but also consider code sequences that are the same except for the linear expression somewhere in it and turn it back into use of a temporary. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/103072] Folding common switch code 2021-11-04 0:01 [Bug tree-optimization/103072] New: Folding common switch code llvm at rifkin dot dev 2021-11-04 8:15 ` [Bug tree-optimization/103072] " jakub at gcc dot gnu.org @ 2021-11-04 9:12 ` rguenth at gcc dot gnu.org 2021-11-04 12:46 ` marxin at gcc dot gnu.org ` (2 subsequent siblings) 4 siblings, 0 replies; 6+ messages in thread From: rguenth at gcc dot gnu.org @ 2021-11-04 9:12 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103072 Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed| |2021-11-04 Status|UNCONFIRMED |NEW Ever confirmed|0 |1 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/103072] Folding common switch code 2021-11-04 0:01 [Bug tree-optimization/103072] New: Folding common switch code llvm at rifkin dot dev 2021-11-04 8:15 ` [Bug tree-optimization/103072] " jakub at gcc dot gnu.org 2021-11-04 9:12 ` rguenth at gcc dot gnu.org @ 2021-11-04 12:46 ` marxin at gcc dot gnu.org 2021-11-04 14:43 ` llvm at rifkin dot dev 2021-11-29 20:35 ` pinskia at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: marxin at gcc dot gnu.org @ 2021-11-04 12:46 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103072 --- Comment #2 from Martin Liška <marxin at gcc dot gnu.org> --- Or we can alternatively merge all the case blocks into one.. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/103072] Folding common switch code 2021-11-04 0:01 [Bug tree-optimization/103072] New: Folding common switch code llvm at rifkin dot dev ` (2 preceding siblings ...) 2021-11-04 12:46 ` marxin at gcc dot gnu.org @ 2021-11-04 14:43 ` llvm at rifkin dot dev 2021-11-29 20:35 ` pinskia at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: llvm at rifkin dot dev @ 2021-11-04 14:43 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103072 --- Comment #3 from Jeremy R. <llvm at rifkin dot dev> --- (In reply to Jakub Jelinek from comment #1) > So maybe the switchconv pass could be > improved not to do just the linear etc. expression handling, but also > consider code sequences that are the same except for the linear expression > somewhere in it and turn it back into use of a temporary. I think this is how LLVM approaches it. It might be nice to be able to fold switches where it's not a linear sequence too, such as: void bar(int x) { switch(x) { case 1: func(x); break; case 4: func(x); break; case 7: func(x); break; case 3: func(x); break; case 9: func(x); break; default: __builtin_unreachable(); } } LLVM is able to fold this out of a switch though it also struggles due to the early constant propagation and doesn't fold this perfectly. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/103072] Folding common switch code 2021-11-04 0:01 [Bug tree-optimization/103072] New: Folding common switch code llvm at rifkin dot dev ` (3 preceding siblings ...) 2021-11-04 14:43 ` llvm at rifkin dot dev @ 2021-11-29 20:35 ` pinskia at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: pinskia at gcc dot gnu.org @ 2021-11-29 20:35 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103072 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |DUPLICATE --- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> --- This is a dup of bug 96245. *** This bug has been marked as a duplicate of bug 96245 *** ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-11-29 20:35 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-11-04 0:01 [Bug tree-optimization/103072] New: Folding common switch code llvm at rifkin dot dev 2021-11-04 8:15 ` [Bug tree-optimization/103072] " jakub at gcc dot gnu.org 2021-11-04 9:12 ` rguenth at gcc dot gnu.org 2021-11-04 12:46 ` marxin at gcc dot gnu.org 2021-11-04 14:43 ` llvm at rifkin dot dev 2021-11-29 20:35 ` 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).