https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101701
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Last reconfirmed| |2021-07-30 Status|UNCONFIRMED |NEW Severity|normal |enhancement --- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> --- So the problem here is iftoswitch should ignore if it is profitable to convert the ifs to a switch statement (unless there are only two ifs) and then allow the switchlower pass to lower the switch again. I thought there was a bug about this already too. What is interesting is that the cost for ifs are so high on arm target (compared to a switch), we end up with the best code already: foo(int): subs r3, r0, #1 cmp r3, #3 it hi movhi r0, #-1 bx lr bar(int): subs r3, r0, #1 cmp r3, #3 it hi movhi r0, #-1 bx lr baz(int): subs r3, r0, #1 cmp r3, #4 it cs movcs r0, #-1 bx lr :) So x86 we get: ;; Canonical GIMPLE case clusters: 1 2 3 4 For foo and then for bar: ;; Canonical GIMPLE case clusters: 1 2 3 4 ;; BT can be built: BT(values:4 comparisons:8 range:4 density: 200.00%):1-4 /app/example.cpp:10:21: optimized: Condition chain with 4 BBs transformed into a switch statement.