Skip to content

Commit 169e599

Browse files
committed
!fixup address latest comments, thanks
1 parent 1702651 commit 169e599

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,6 @@ class VPInstruction : public VPRecipeWithIRFlags,
865865
CalculateTripCountMinusVF,
866866
// Increment the canonical IV separately for each unrolled part.
867867
CanonicalIVIncrementForPart,
868-
WideIVStep,
869868
BranchOnCount,
870869
BranchOnCond,
871870
Broadcast,
@@ -885,6 +884,13 @@ class VPInstruction : public VPRecipeWithIRFlags,
885884
AnyOf,
886885
// Calculates the first active lane index of the vector predicate operand.
887886
FirstActiveLane,
887+
888+
// The opcodes below are used for VPInstructionWithType.
889+
//
890+
/// Scale the first operand (vector step) by the second operand
891+
/// (scalar-step). Casts both operands to the result type if needed.
892+
WideIVStep,
893+
888894
};
889895

890896
private:
@@ -1051,9 +1057,10 @@ class VPInstructionWithType : public VPInstruction {
10511057
static inline bool classof(const VPRecipeBase *R) {
10521058
// VPInstructionWithType are VPInstructions with specific opcodes requiring
10531059
// type information.
1060+
if (R->isScalarCast())
1061+
return true;
10541062
auto *VPI = dyn_cast<VPInstruction>(R);
1055-
return R->isScalarCast() ||
1056-
(VPI && VPI->getOpcode() == VPInstruction::WideIVStep);
1063+
return VPI && VPI->getOpcode() == VPInstruction::WideIVStep;
10571064
}
10581065

10591066
static inline bool classof(const VPUser *R) {

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ void VPInstructionWithType::print(raw_ostream &O, const Twine &Indent,
11031103

11041104
switch (getOpcode()) {
11051105
case VPInstruction::WideIVStep:
1106-
O << "wide-iv-step";
1106+
O << "wide-iv-step ";
11071107
printOperands(O, SlotTracker);
11081108
break;
11091109
default:

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,10 +1023,8 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
10231023
if (match(&R, m_VPInstruction<VPInstruction::WideIVStep>(m_VPValue(X),
10241024
m_SpecificInt(1)))) {
10251025
Type *WideStepTy = TypeInfo.inferScalarType(R.getVPSingleValue());
1026-
if (TypeInfo.inferScalarType(X) != WideStepTy) {
1027-
X = new VPWidenCastRecipe(Instruction::Trunc, X, WideStepTy);
1028-
X->getDefiningRecipe()->insertBefore(&R);
1029-
}
1026+
if (TypeInfo.inferScalarType(X) != WideStepTy)
1027+
X = VPBuilder(&R).createWidenCast(Instruction::Trunc, X, WideStepTy);
10301028
R.getVPSingleValue()->replaceAllUsesWith(X);
10311029
}
10321030
}
@@ -2381,6 +2379,7 @@ void VPlanTransforms::convertToConcreteRecipes(VPlan &Plan,
23812379
VPTypeAnalysis &TypeInfo) {
23822380
using namespace llvm::VPlanPatternMatch;
23832381

2382+
SmallVector<VPRecipeBase *> ToRemove;
23842383
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
23852384
vp_depth_first_deep(Plan.getEntry()))) {
23862385
for (VPRecipeBase &R : make_early_inc_range(*VPBB)) {
@@ -2393,7 +2392,7 @@ void VPlanTransforms::convertToConcreteRecipes(VPlan &Plan,
23932392
PhiR->getDebugLoc(), Name);
23942393
ScalarR->insertBefore(PhiR);
23952394
PhiR->replaceAllUsesWith(ScalarR);
2396-
PhiR->eraseFromParent();
2395+
ToRemove.push_back(PhiR);
23972396
continue;
23982397
}
23992398

@@ -2402,8 +2401,10 @@ void VPlanTransforms::convertToConcreteRecipes(VPlan &Plan,
24022401
if (!match(&R, m_VPInstruction<VPInstruction::WideIVStep>(
24032402
m_VPValue(VectorStep), m_VPValue(ScalarStep))))
24042403
continue;
2404+
2405+
// Expand WideIVStep.
24052406
auto *VPI = cast<VPInstruction>(&R);
2406-
VPBuilder Builder(VPI->getParent(), VPI->getIterator());
2407+
VPBuilder Builder(VPI);
24072408
Type *IVTy = TypeInfo.inferScalarType(VPI);
24082409
if (TypeInfo.inferScalarType(VectorStep) != IVTy) {
24092410
Instruction::CastOps CastOp = IVTy->isFloatingPointTy()
@@ -2432,9 +2433,12 @@ void VPlanTransforms::convertToConcreteRecipes(VPlan &Plan,
24322433
MulOpc, {VectorStep, ScalarStep}, FMFs, R.getDebugLoc());
24332434
VectorStep = Mul;
24342435
VPI->replaceAllUsesWith(VectorStep);
2435-
VPI->eraseFromParent();
2436+
ToRemove.push_back(VPI);
24362437
}
24372438
}
2439+
2440+
for (VPRecipeBase *R : ToRemove)
2441+
R->eraseFromParent();
24382442
}
24392443

24402444
void VPlanTransforms::handleUncountableEarlyExit(

0 commit comments

Comments
 (0)