https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119057
--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> --- So there's code in check_reduction_path that checks for additional uses of the path defs that explicitly allows out-of-loop uses for the "tail": /* Check there's only a single stmt the op is used on. For the not value-changing tail and the last stmt allow out-of-loop uses. ??? We could relax this and handle arbitrary live stmts by forcing a scalar epilogue for example. */ ... else if (!is_gimple_debug (op_use_stmt) && (*code != ERROR_MARK || flow_bb_inside_loop_p (loop, gimple_bb (op_use_stmt)))) FOR_EACH_IMM_USE_ON_STMT (use_p, imm_iter) cnt++; we have <bb 4> [local count: 955630224]: # a.1_28 = PHI <_2(9), a.1_6(3)> # b_lsm.15_27 = PHI <_25(9), b_lsm.15_33(3)> <--- # c_lsm.17_3 = PHI <_20(9), c_lsm.17_26(3)> <bb 5> [local count: 7731917314]: # d.6_31 = PHI <_14(10), 0(4)> # b_lsm.15_13 = PHI <_12(10), b_lsm.15_27(4)> <--- # ivtmp_23 = PHI <ivtmp_22(10), 2(4)> b.3_9 = (unsigned int) b_lsm.15_13; <--- _11 = b.3_9 | e.4_10; <--- (*) _12 = (int) _11; <--- _14 = d.6_31 + 1; ivtmp_22 = ivtmp_23 - 1; if (ivtmp_22 != 0) goto <bb 10>; [89.00%] else goto <bb 6>; [11.00%] <bb 6> [local count: 955630224]: # _51 = PHI <_11(5)> (*) # _25 = PHI <_12(5)> <--- c.9_18 = (unsigned int) c_lsm.17_3; _19 = _51 | c.9_18; with the (*) def being used outside of (the inner) loop. That's undesirable behavior for the double-reduction case. Testing a patch.