https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109154
--- Comment #51 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Dumb untested patch which saves 2 instructions from each of those testcases: --- gcc/tree-if-conv.cc.jj 2023-04-12 08:53:58.264496474 +0200 +++ gcc/tree-if-conv.cc 2023-04-14 21:02:42.403826690 +0200 @@ -2071,7 +2071,7 @@ predicate_scalar_phi (gphi *phi, gimple_ } /* Put element with max number of occurences to the end of ARGS. */ - if (max_ind != -1 && max_ind +1 != (int) args_len) + if (max_ind != -1 && max_ind + 1 != (int) args_len) std::swap (args[args_len - 1], args[max_ind]); /* Handle one special case when number of arguments with different values @@ -2116,12 +2116,12 @@ predicate_scalar_phi (gphi *phi, gimple_ vec<int> *indexes; tree type = TREE_TYPE (gimple_phi_result (phi)); tree lhs; - arg1 = args[1]; - for (i = 0; i < args_len; i++) + arg1 = args[args_len - 1]; + for (i = args_len - 1; i > 0; i--) { - arg0 = args[i]; - indexes = phi_arg_map.get (args[i]); - if (i != args_len - 1) + arg0 = args[i - 1]; + indexes = phi_arg_map.get (args[i - 1]); + if (i != 1) lhs = make_temp_ssa_name (type, NULL, "_ifc_"); else lhs = res;