[llvm] [LV] Emit truncate for widen-induction in VPlan during construction. (PR #225991)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 2 11:52:42 PDT 2026
================
@@ -7581,6 +7581,20 @@ static SmallVector<Instruction *> preparePlanForEpilogueVectorLoop(
}
assert(ResumeV && "Must have a resume value");
VPValue *StartVal = Plan.getOrAddLiveIn(ResumeV);
+ auto *PhiR = dyn_cast<VPWidenIntOrFpInductionRecipe>(&R);
+ // A truncated widen induction has narrower type than resume value, so
+ // create a scalar cast to match the type.
+ if (PhiR && PhiR->getScalarType() != StartVal->getScalarType()) {
+ assert(StartVal->getScalarType()->getScalarSizeInBits() >
+ PhiR->getScalarType()->getScalarSizeInBits() &&
+ "Widen induction type should always narrower or same as resume "
+ "value type.");
+ VPBuilder PHBuilder(Plan.getVectorPreheader(),
+ Plan.getVectorPreheader()->getFirstNonPhi());
+ StartVal = PHBuilder.createScalarCast(Instruction::Trunc, StartVal,
+ PhiR->getScalarType(),
+ PhiR->getDebugLoc());
----------------
artagnon wrote:
Would it be possible to keep a reference to the new VPInstruction in WidenIntOrFpRecipe now, instead of having to dig for it every time?
https://github.com/llvm/llvm-project/pull/225991
More information about the llvm-commits
mailing list