Skip to content

Commit 8a56179

Browse files
committed
[VPlan] Store induction kind & binop directly in VPDerviedIVRecipe(NFC)
Limit the information stored in VPDerivedIVRecipe to the ingredients really needed.
1 parent dea33c8 commit 8a56179

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2386,7 +2386,7 @@ static Value *
23862386
emitTransformedIndex(IRBuilderBase &B, Value *Index, Value *StartValue,
23872387
Value *Step,
23882388
InductionDescriptor::InductionKind InductionKind,
2389-
BinaryOperator *InductionBinOp) {
2389+
const BinaryOperator *InductionBinOp) {
23902390
Type *StepTy = Step->getType();
23912391
Value *CastedIndex = StepTy->isIntegerTy()
23922392
? B.CreateSExtOrTrunc(Index, StepTy)
@@ -9479,19 +9479,17 @@ void VPDerivedIVRecipe::execute(VPTransformState &State) {
94799479

94809480
// Fast-math-flags propagate from the original induction instruction.
94819481
IRBuilder<>::FastMathFlagGuard FMFG(State.Builder);
9482-
if (IndDesc.getInductionBinOp() &&
9483-
isa<FPMathOperator>(IndDesc.getInductionBinOp()))
9484-
State.Builder.setFastMathFlags(
9485-
IndDesc.getInductionBinOp()->getFastMathFlags());
9482+
if (BinOp && isa<FPMathOperator>(BinOp))
9483+
State.Builder.setFastMathFlags(BinOp->getFastMathFlags());
94869484

94879485
Value *Step = State.get(getStepValue(), VPIteration(0, 0));
94889486
Value *CanonicalIV = State.get(getCanonicalIV(), VPIteration(0, 0));
9489-
Value *DerivedIV = emitTransformedIndex(
9490-
State.Builder, CanonicalIV, getStartValue()->getLiveInIRValue(), Step,
9491-
IndDesc.getKind(), IndDesc.getInductionBinOp());
9487+
Value *DerivedIV = emitTransformedIndex(State.Builder, CanonicalIV,
9488+
getStartValue()->getLiveInIRValue(),
9489+
Step, Kind, BinOp);
94929490
DerivedIV->setName("offset.idx");
94939491
if (ResultTy != DerivedIV->getType()) {
9494-
assert(Step->getType()->isIntegerTy() &&
9492+
assert(IsTruncated && Step->getType()->isIntegerTy() &&
94959493
"Truncation requires an integer step");
94969494
DerivedIV = State.Builder.CreateTrunc(DerivedIV, ResultTy);
94979495
}

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,15 +2143,20 @@ class VPDerivedIVRecipe : public VPRecipeBase, public VPValue {
21432143
/// induction and in this case it will get truncated to ResultTy.
21442144
Type *ResultTy;
21452145

2146+
bool IsTruncated;
2147+
21462148
/// Induction descriptor for the induction the canonical IV is transformed to.
2147-
const InductionDescriptor &IndDesc;
2149+
const InductionDescriptor::InductionKind Kind;
2150+
const BinaryOperator *BinOp;
21482151

21492152
public:
21502153
VPDerivedIVRecipe(const InductionDescriptor &IndDesc, VPValue *Start,
21512154
VPCanonicalIVPHIRecipe *CanonicalIV, VPValue *Step,
21522155
Type *ResultTy)
21532156
: VPRecipeBase(VPDef::VPDerivedIVSC, {Start, CanonicalIV, Step}),
2154-
VPValue(this), ResultTy(ResultTy), IndDesc(IndDesc) {}
2157+
VPValue(this), ResultTy(ResultTy),
2158+
IsTruncated(IndDesc.getStep()->getType() != ResultTy),
2159+
Kind(IndDesc.getKind()), BinOp(IndDesc.getInductionBinOp()) {}
21552160

21562161
~VPDerivedIVRecipe() override = default;
21572162

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

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

800-
if (IndDesc.getStep()->getType() != ResultTy)
800+
if (IsTruncated)
801801
O << " (truncated to " << *ResultTy << ")";
802802
}
803803
#endif

0 commit comments

Comments
 (0)