Skip to content

Commit 7cf85b9

Browse files
committed
Infer and check types instead of peeking through underlying value for trunc
1 parent 55deb1c commit 7cf85b9

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,13 +2545,11 @@ expandVPWidenIntOrFpInduction(VPWidenIntOrFpInductionRecipe *WidenIVR,
25452545
VPValue *Start = WidenIVR->getStartValue();
25462546
VPValue *Step = WidenIVR->getStepValue();
25472547
VPValue *VF = WidenIVR->getVFValue();
2548-
TruncInst *Trunc = WidenIVR->getTruncInst();
25492548
DebugLoc DL = WidenIVR->getDebugLoc();
25502549

25512550
// The value from the original loop to which we are mapping the new induction
25522551
// variable.
2553-
Instruction *IV = Trunc ? cast<Instruction>(Trunc) : WidenIVR->getPHINode();
2554-
Type *Ty = IV->getType();
2552+
Type *Ty = TypeInfo.inferScalarType(WidenIVR);
25552553

25562554
const InductionDescriptor &ID = WidenIVR->getInductionDescriptor();
25572555
Instruction::BinaryOps AddOp;
@@ -2568,17 +2566,17 @@ expandVPWidenIntOrFpInduction(VPWidenIntOrFpInductionRecipe *WidenIVR,
25682566

25692567
// If the phi is truncated, truncate the start and step values.
25702568
VPBuilder Builder(Plan->getVectorPreheader());
2571-
if (isa<TruncInst>(IV)) {
2572-
assert(TypeInfo.inferScalarType(Start)->isIntegerTy() &&
2573-
"Truncation requires an integer type");
2569+
Type *StepTy = TypeInfo.inferScalarType(Step);
2570+
if (Ty->getScalarSizeInBits() < StepTy->getScalarSizeInBits()) {
2571+
assert(StepTy->isIntegerTy() && "Truncation requires an integer type");
25742572
Step = Builder.createScalarCast(Instruction::Trunc, Step, Ty, DL);
25752573
Start = Builder.createScalarCast(Instruction::Trunc, Start, Ty, DL);
2574+
StepTy = Ty;
25762575
}
25772576

25782577
// Construct the initial value of the vector IV in the vector loop preheader.
2579-
Type *StepTy = TypeInfo.inferScalarType(Step);
25802578
Type *IVIntTy =
2581-
IntegerType::get(IV->getContext(), StepTy->getScalarSizeInBits());
2579+
IntegerType::get(StepTy->getContext(), StepTy->getScalarSizeInBits());
25822580
VPValue *Init = Builder.createNaryOp(VPInstruction::StepVector, {}, IVIntTy);
25832581
if (StepTy->isFloatingPointTy())
25842582
Init = Builder.createWidenCast(Instruction::UIToFP, Init, StepTy);

0 commit comments

Comments
 (0)