https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113741
Bug ID: 113741 Summary: missed / wrong optimization switch transformation to same function call Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: b.buschinski at googlemail dot com Target Milestone: --- Created attachment 57308 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57308&action=edit Attached code + asm from the compiler explorer link Compiler Explorer Link: https://godbolt.org/z/KozK9M5YY The code is reduced from a "hot" path with huge macros. I actually improved the macros with adding the "else" in the code, but I noticed it suddenly created even more instructions and got slower. The GCC version has 52 ASM lines. The clang version only 9 ASM lines. Clang is doing a better job here. As far as I understand the ASM code, GCC generates a switch statement, but after the: cmp edi, 5 ja .L11 it should not be needed at all anymore. Additionally, GCC "reloads" the static values again (for every .L*: label) mov edi, 4 , which are already stored in "i" (C code). Tested with GCC-13.2 and compiler explorer gcc "trunk". On x86_64 Linux. Please let me know if you need any additional details or if this report was useful at all.