[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
Wed Apr 15 05:49:55 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:
I don't think this is correct; if we condition is never true, we must return the original start value of the FindIV reductions, not the start value of the induction I think
https://github.com/llvm/llvm-project/pull/192054
More information about the llvm-commits
mailing list