[llvm] [VPlan] Replace ComputeFindIVRes with ComputeRdxRes + cmp + sel (NFC) (PR #176672)
Mel Chen via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 20 01:14:01 PST 2026
================
@@ -9473,23 +9469,33 @@ static SmallVector<Instruction *> preparePlanForEpilogueVectorLoop(
if (auto *I = dyn_cast<Instruction>(ResumeV))
InstsToMove.push_back(I);
} else if (RecurrenceDescriptor::isFindIVRecurrenceKind(RK)) {
- Value *StartV = getStartValueFromReductionResult(RdxResult);
- ToFrozen[StartV] = cast<PHINode>(ResumeV)->getIncomingValueForBlock(
+ using namespace VPlanPatternMatch;
+ // Find the icmp user of RdxResult to get the sentinel value.
+ // The pattern is: select(icmp ne RdxResult, Sentinel), RdxResult, Start
+ VPValue *SentinelVPV = nullptr;
+ for (VPUser *U : RdxResult->users()) {
+ if (match(U, VPlanPatternMatch::m_SpecificICmp(
+ ICmpInst::ICMP_NE, m_Specific(RdxResult),
+ m_VPValue(SentinelVPV))))
+ break;
+ }
+ assert(SentinelVPV && "expected to find icmp using RdxResult");
----------------
Mel-Chen wrote:
Will this work?
```suggestion
[[maybe_unused]] bool Found = any_of(RdxResult->users(), [&](VPUser *U) {
return match(U, m_SpecificICmp(ICmpInst::ICMP_NE, m_Specific(RdxResult),
m_VPValue(SentinelVPV)));
});
assert(Found && "expected to find icmp using RdxResult");
```
https://github.com/llvm/llvm-project/pull/176672
More information about the llvm-commits
mailing list