Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions llvm/lib/Transforms/Vectorize/VPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,6 @@ class VPInstruction : public VPRecipeWithIRFlags,
CalculateTripCountMinusVF,
// Increment the canonical IV separately for each unrolled part.
CanonicalIVIncrementForPart,
WideIVStep,
BranchOnCount,
BranchOnCond,
Broadcast,
Expand All @@ -885,6 +884,13 @@ class VPInstruction : public VPRecipeWithIRFlags,
AnyOf,
// Calculates the first active lane index of the vector predicate operand.
FirstActiveLane,

// The opcodes below are used for VPInstructionWithType.
//
/// Scale the first operand (vector step) by the second operand
/// (scalar-step). Casts both operands to the result type if needed.
WideIVStep,

};

private:
Expand Down Expand Up @@ -1051,9 +1057,10 @@ class VPInstructionWithType : public VPInstruction {
static inline bool classof(const VPRecipeBase *R) {
// VPInstructionWithType are VPInstructions with specific opcodes requiring
// type information.
if (R->isScalarCast())
return true;
auto *VPI = dyn_cast<VPInstruction>(R);
return R->isScalarCast() ||
(VPI && VPI->getOpcode() == VPInstruction::WideIVStep);
return VPI && VPI->getOpcode() == VPInstruction::WideIVStep;
}

static inline bool classof(const VPUser *R) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ void VPInstructionWithType::print(raw_ostream &O, const Twine &Indent,

switch (getOpcode()) {
case VPInstruction::WideIVStep:
O << "wide-iv-step";
O << "wide-iv-step ";
printOperands(O, SlotTracker);
break;
default:
Expand Down
18 changes: 11 additions & 7 deletions llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1023,10 +1023,8 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
if (match(&R, m_VPInstruction<VPInstruction::WideIVStep>(m_VPValue(X),
m_SpecificInt(1)))) {
Type *WideStepTy = TypeInfo.inferScalarType(R.getVPSingleValue());
if (TypeInfo.inferScalarType(X) != WideStepTy) {
X = new VPWidenCastRecipe(Instruction::Trunc, X, WideStepTy);
X->getDefiningRecipe()->insertBefore(&R);
}
if (TypeInfo.inferScalarType(X) != WideStepTy)
X = VPBuilder(&R).createWidenCast(Instruction::Trunc, X, WideStepTy);
R.getVPSingleValue()->replaceAllUsesWith(X);
}
}
Expand Down Expand Up @@ -2381,6 +2379,7 @@ void VPlanTransforms::convertToConcreteRecipes(VPlan &Plan,
VPTypeAnalysis &TypeInfo) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just pass in the canonical IV and construct the TypeInfo in convertToConcreteRecipes, since I think it'll be invalid once convertToConcreteRecipes returns

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I think it would be clearer to pass the type analysis interface wise, but undone for now, until your patch lands adding support for invalidating entries.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I can break that off into a separate patch if you'd like

using namespace llvm::VPlanPatternMatch;

SmallVector<VPRecipeBase *> ToRemove;
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
vp_depth_first_deep(Plan.getEntry()))) {
for (VPRecipeBase &R : make_early_inc_range(*VPBB)) {
Expand All @@ -2393,7 +2392,7 @@ void VPlanTransforms::convertToConcreteRecipes(VPlan &Plan,
PhiR->getDebugLoc(), Name);
ScalarR->insertBefore(PhiR);
PhiR->replaceAllUsesWith(ScalarR);
PhiR->eraseFromParent();
ToRemove.push_back(PhiR);
continue;
}

Expand All @@ -2402,8 +2401,10 @@ void VPlanTransforms::convertToConcreteRecipes(VPlan &Plan,
if (!match(&R, m_VPInstruction<VPInstruction::WideIVStep>(
m_VPValue(VectorStep), m_VPValue(ScalarStep))))
continue;

// Expand WideIVStep.
auto *VPI = cast<VPInstruction>(&R);
VPBuilder Builder(VPI->getParent(), VPI->getIterator());
VPBuilder Builder(VPI);
Type *IVTy = TypeInfo.inferScalarType(VPI);
if (TypeInfo.inferScalarType(VectorStep) != IVTy) {
Instruction::CastOps CastOp = IVTy->isFloatingPointTy()
Expand Down Expand Up @@ -2432,9 +2433,12 @@ void VPlanTransforms::convertToConcreteRecipes(VPlan &Plan,
MulOpc, {VectorStep, ScalarStep}, FMFs, R.getDebugLoc());
VectorStep = Mul;
VPI->replaceAllUsesWith(VectorStep);
VPI->eraseFromParent();
ToRemove.push_back(VPI);
}
}

for (VPRecipeBase *R : ToRemove)
R->eraseFromParent();
}

void VPlanTransforms::handleUncountableEarlyExit(
Expand Down
Loading