https://gcc.gnu.org/bugzilla/show_bug.cgi?id=40748
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Component|middle-end |tree-optimization --- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> --- So we handle f1 and foo correctly since GCC 9 (well almost, f1 is handled correctly on the trunk that is turn into MIN_EXPR which happens because PHI-OPT uses match-and-simplify which was done in r12-1152). f3 has always been handled. f2 is the one which is not handled, GCC knows how to convert it to a switch table but does not because of "cost". Here is a similar function which messes up GCC and LLVM fully and never recovers (for GCC it started in 11, for clang it started in clang 12): unsigned f2(unsigned i) { if (i == 0) return 0; if (i == 1) return 1; if (i == 2) return 2; if (i == 3) return 3; if (i == 4) return 4; if (i == 5) return 4; if (i == 6) return 4; return 4; }