https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107740
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Target Milestone|--- |12.3 Last reconfirmed| |2022-11-17 Status|UNCONFIRMED |NEW Summary|if-to-switch conversion |[12/13 Regression] |happens for simple |if-to-switch conversion |predicate function when |happens for simple |compiled with gcc but not |predicate function when |with g++ |compiled with gcc but not | |with g++ --- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> --- The difference is PHI-OPT: For C++ we have: _4 = c_8(D) == 13; _5 = c_8(D) == 9; _6 = _4 | _5; if (_6 != 0) goto <bb 4>; [INV] else goto <bb 5>; [INV] <bb 4> : <bb 5> : # iftmp.0_7 = PHI <1(4), 0(3)> Which phi-opt1 changes to: _4 = c_8(D) == 13; _5 = c_8(D) == 9; _6 = _4 | _5; <bb 4> : # iftmp.0_7 = PHI <1(2), _6(3)> (note type is bool) But for C we have: if (_6 != 0) goto <bb 4>; [INV] else goto <bb 5>; [INV] <bb 4> : <bb 5> : # iftmp.0_7 = PHI <1(4), 0(3)> (note the type is int) phi-opt1 is the "early phi-opt" which tries not to do it here. Also this is a regression from GCC 11.3.0. There has been improvements to phi-opt and there was slight IR change due to cleanup cfg after cddce1 which allowed phi-opt to do the change here. Note PHI-OPT is not at fault really but if-to-switch not handling the slightly different IR really.