https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105740
Bug ID: 105740
Summary: missed optimization switch transformation for
conditions with duplicate conditions
Product: gcc
Version: 12.1.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 53037
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53037&action=edit
Attached code + asm from the compiler explorer link
Compiler Explorer Link: https://godbolt.org/z/q76s99Gj9
The code on the left does not generate a switch statement.
The code on the right does generate a switch statement.
The code works similar, the only difference is that the duplicate "f->len > 3"
check is moved to the top for the "right" version.
The compiler explorer code is actually a minimized version of the code I work
on (with way more conditions in a hot code path), where I can not easily move
the length check to the top, because the "f-> len > 3 && ..." is done in a very
complicated macro, but that's just details.
I expected both code versions to generate the same assembler.
Tested with GCC-12.1 and 11.3. 10.3 does not generate a switch version for both
versions, as only 11 got this nice feature.
On x86_64 Linux.
Please let me know if you need any additional details or if this report was
useful at all.