Skip to content

Commit a48ebb8

Browse files
committed
[VPlan] Check type directly in ::isCanonical (NFC).
Directly check the type of the wide induction matches the canonical induction. Refactor suggested in and in preparation for #89603
1 parent fcf86cc commit a48ebb8

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1757,7 +1757,8 @@ class VPWidenIntOrFpInductionRecipe : public VPHeaderPHIRecipe {
17571757
const InductionDescriptor &getInductionDescriptor() const { return IndDesc; }
17581758

17591759
/// Returns true if the induction is canonical, i.e. starting at 0 and
1760-
/// incremented by UF * VF (= the original IV is incremented by 1).
1760+
/// incremented by UF * VF (= the original IV is incremented by 1) and has the
1761+
/// same type as the canonical induction.
17611762
bool isCanonical() const;
17621763

17631764
/// Returns the scalar type of the induction.

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,9 @@ bool VPWidenIntOrFpInductionRecipe::isCanonical() const {
12221222
return false;
12231223
auto *StepC = dyn_cast<ConstantInt>(getStepValue()->getLiveInIRValue());
12241224
auto *StartC = dyn_cast<ConstantInt>(getStartValue()->getLiveInIRValue());
1225-
return StartC && StartC->isZero() && StepC && StepC->isOne();
1225+
auto *CanIV = cast<VPCanonicalIVPHIRecipe>(&*getParent()->begin());
1226+
return StartC && StartC->isZero() && StepC && StepC->isOne() &&
1227+
getScalarType() == CanIV->getScalarType();
12261228
}
12271229

12281230
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,7 @@ static void removeRedundantCanonicalIVs(VPlan &Plan) {
452452
for (VPRecipeBase &Phi : HeaderVPBB->phis()) {
453453
auto *WidenOriginalIV = dyn_cast<VPWidenIntOrFpInductionRecipe>(&Phi);
454454

455-
if (!WidenOriginalIV || !WidenOriginalIV->isCanonical() ||
456-
WidenOriginalIV->getScalarType() != WidenNewIV->getScalarType())
455+
if (!WidenOriginalIV || !WidenOriginalIV->isCanonical())
457456
continue;
458457

459458
// Replace WidenNewIV with WidenOriginalIV if WidenOriginalIV provides

0 commit comments

Comments
 (0)