[llvm] [LV] Fix handleFirstArgMinOrMax to use 0 as identity element for UMax/SMax (PR #192054)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 16 05:01:22 PDT 2026
================
@@ -1779,14 +1785,11 @@ static bool handleFirstArgMinOrMax(
FinalCanIV = DerivedIVRecipe;
}
- // If the final min/max value matches its start value, the condition in the
- // loop was always false, i.e. no induction value has been selected. If that's
- // the case, set the result of the IV reduction to its start value.
- VPValue *AlwaysFalse = Builder.createICmp(CmpInst::ICMP_EQ, MinOrMaxResult,
- MinOrMaxPhiR->getStartValue());
- VPValue *FinalIV = Builder.createSelect(
- AlwaysFalse, FindIVSelect->getOperand(2), FinalCanIV);
- FindIVSelect->replaceAllUsesWith(FinalIV);
+ // Replace the previous FindIV result with the new canonical IV result.
+ // No guard needed: when the condition is never true, FindLastIVPhiR is
+ // initialized with 0, so RawCanIV = 0 and FinalCanIV correctly returns the
+ // start value of the original IV.
+ FindIVSelect->replaceAllUsesWith(FinalCanIV);
----------------
fhahn wrote:
> FinalCanIV = DerivedIV(start_value, 0, step) = start_value,
That is the start value of the tracked IV, but the start value of the FindIV reduction may be different to that value, as in `@argmin_argmax` for example?
https://github.com/llvm/llvm-project/pull/192054
More information about the llvm-commits
mailing list