Skip to content

Commit aacaf3d

Browse files
committed
[VPlan] Simplify VPDerivedIV truncation handling (NFCI).
Address post-commit simplification suggestion for 8a56179: Replace IsTruncated by conditionally setting TruncResultTy only if truncation is required.
1 parent 1688868 commit aacaf3d

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9488,10 +9488,11 @@ void VPDerivedIVRecipe::execute(VPTransformState &State) {
94889488
getStartValue()->getLiveInIRValue(),
94899489
Step, Kind, BinOp);
94909490
DerivedIV->setName("offset.idx");
9491-
if (ResultTy != DerivedIV->getType()) {
9492-
assert(IsTruncated && Step->getType()->isIntegerTy() &&
9491+
if (TruncResultTy) {
9492+
assert(TruncResultTy != DerivedIV->getType() &&
9493+
Step->getType()->isIntegerTy() &&
94939494
"Truncation requires an integer step");
9494-
DerivedIV = State.Builder.CreateTrunc(DerivedIV, ResultTy);
9495+
DerivedIV = State.Builder.CreateTrunc(DerivedIV, TruncResultTy);
94959496
}
94969497
assert(DerivedIV != CanonicalIV && "IV didn't need transforming?");
94979498

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,24 +2139,21 @@ class VPWidenCanonicalIVRecipe : public VPRecipeBase, public VPValue {
21392139
/// an IV with different start and step values, using Start + CanonicalIV *
21402140
/// Step.
21412141
class VPDerivedIVRecipe : public VPRecipeBase, public VPValue {
2142-
/// The type of the result value. It may be smaller than the type of the
2143-
/// induction and in this case it will get truncated to ResultTy.
2144-
Type *ResultTy;
2145-
2146-
bool IsTruncated;
2142+
/// If not nullptr, the result of the induction will get truncated to
2143+
/// TruncResultTy.
2144+
Type *TruncResultTy;
21472145

2148-
/// Induction descriptor for the induction the canonical IV is transformed to.
2146+
/// Kind and binary operator of the induction.
21492147
const InductionDescriptor::InductionKind Kind;
21502148
const BinaryOperator *BinOp;
21512149

21522150
public:
21532151
VPDerivedIVRecipe(const InductionDescriptor &IndDesc, VPValue *Start,
21542152
VPCanonicalIVPHIRecipe *CanonicalIV, VPValue *Step,
2155-
Type *ResultTy)
2153+
Type *TruncResultTy)
21562154
: VPRecipeBase(VPDef::VPDerivedIVSC, {Start, CanonicalIV, Step}),
2157-
VPValue(this), ResultTy(ResultTy),
2158-
IsTruncated(IndDesc.getStep()->getType() != ResultTy),
2159-
Kind(IndDesc.getKind()), BinOp(IndDesc.getInductionBinOp()) {}
2155+
VPValue(this), TruncResultTy(TruncResultTy), Kind(IndDesc.getKind()),
2156+
BinOp(IndDesc.getInductionBinOp()) {}
21602157

21612158
~VPDerivedIVRecipe() override = default;
21622159

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -797,8 +797,8 @@ void VPDerivedIVRecipe::print(raw_ostream &O, const Twine &Indent,
797797
O << " * ";
798798
getStepValue()->printAsOperand(O, SlotTracker);
799799

800-
if (IsTruncated)
801-
O << " (truncated to " << *ResultTy << ")";
800+
if (TruncResultTy)
801+
O << " (truncated to " << *TruncResultTy << ")";
802802
}
803803
#endif
804804

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,8 @@ static VPValue *createScalarIVSteps(VPlan &Plan, const InductionDescriptor &ID,
511511
Type *TruncTy = TruncI ? TruncI->getType() : IVTy;
512512
VPValue *BaseIV = CanonicalIV;
513513
if (!CanonicalIV->isCanonical(ID.getKind(), StartV, Step, TruncTy)) {
514-
BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step, TruncTy);
514+
BaseIV = new VPDerivedIVRecipe(ID, StartV, CanonicalIV, Step,
515+
TruncI ? TruncI->getType() : nullptr);
515516
HeaderVPBB->insert(BaseIV->getDefiningRecipe(), IP);
516517
}
517518

0 commit comments

Comments
 (0)