https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113134
--- Comment #22 from JuzheZhong <juzhe.zhong at rivai dot ai> --- I have done this following experiment. diff --git a/gcc/tree-ssa-loop-ivcanon.cc b/gcc/tree-ssa-loop-ivcanon.cc index bf017137260..8c36cc63d3b 100644 --- a/gcc/tree-ssa-loop-ivcanon.cc +++ b/gcc/tree-ssa-loop-ivcanon.cc @@ -1260,6 +1260,39 @@ canonicalize_loop_induction_variables (class loop *loop, may_be_zero = false; } + if (!exit) + { + auto_vec<edge> exits = get_loop_exit_edges (loop); + exit = exits[0]; + class tree_niter_desc desc1; + class tree_niter_desc desc2; + if (number_of_iterations_exit (loop, exits[0], &desc1, false) + && number_of_iterations_exit (loop, exits[1], &desc2, false)) + { + niter = fold_build2 (MIN_EXPR, unsigned_type_node, desc1.niter, + desc2.niter); + create_canonical_iv (loop, exit, niter); + gcond *cond_stmt; + class nb_iter_bound *elt; + for (elt = loop->bounds; elt; elt = elt->next) + { + if (elt->is_exit + && !wi::ltu_p (loop->nb_iterations_upper_bound, + elt->bound)) + { + cond_stmt = as_a <gcond *> (elt->stmt); + break; + } + } + if (exits[1]->flags & EDGE_TRUE_VALUE) + gimple_cond_make_false (cond_stmt); + else + gimple_cond_make_true (cond_stmt); + update_stmt (cond_stmt); + return false; + } + } + I know the check is wrong just for experiment, Then: <bb 2> [local count: 69202658]: _21 = (unsigned int) N_13(D); _22 = MIN_EXPR <_21, 1001>; ---- > Use MIN_EXPR as the check. _23 = _22 + 1; goto <bb 5>; [100.00%] <bb 3> [local count: 1014686025]: _1 = (long unsigned int) i_9; _2 = _1 * 4; _3 = a_14(D) + _2; _4 = *_3; _5 = b_15(D) + _2; _6 = *_5; _7 = c_16(D) + _2; _8 = _4 + _6; *_7 = _8; if (0 != 0) goto <bb 6>; [1.00%] else goto <bb 4>; [99.00%] <bb 4> [local count: 1004539166]: i_18 = i_9 + 1; <bb 5> [local count: 1073741824]: # i_9 = PHI <0(2), i_18(4)> # ivtmp_19 = PHI <_23(2), ivtmp_20(4)> ivtmp_20 = ivtmp_19 - 1; if (ivtmp_20 != 0) goto <bb 3>; [94.50%] else goto <bb 6>; [5.50%] <bb 6> [local count: 69202658]: return; Then it can vectorize. I am not sure whether it is the right place to put the codes.