Skip to content

Commit 83fafe3

Browse files
committed
Respond to review comments
* Document range is to VF * Move private method above * Merge classof checks * Use VPBuilder * Add assertion method
1 parent 5d307e4 commit 83fafe3

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,11 @@ class VPBuilder {
177177
Type *ResultTy,
178178
std::optional<FastMathFlags> FMFs = {},
179179
DebugLoc DL = {}, const Twine &Name = "") {
180-
return tryInsertInstruction(new VPInstructionWithType(
181-
Opcode, Operands, ResultTy, FMFs.value_or(FastMathFlags()), DL, Name));
180+
if (FMFs)
181+
return tryInsertInstruction(new VPInstructionWithType(
182+
Opcode, Operands, ResultTy, *FMFs, DL, Name));
183+
return tryInsertInstruction(
184+
new VPInstructionWithType(Opcode, Operands, ResultTy, DL, Name));
182185
}
183186

184187
VPInstruction *createOverflowingOp(unsigned Opcode,

llvm/lib/Transforms/Vectorize/VPlan.h

+12-8
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ class VPInstruction : public VPRecipeWithIRFlags,
898898
/// Scale the first operand (vector step) by the second operand
899899
/// (scalar-step). Casts both operands to the result type if needed.
900900
WideIVStep,
901-
// Creates a step vector starting from 0 with a step of 1.
901+
// Creates a step vector starting from 0 to VF with a step of 1.
902902
StepVector,
903903

904904
};
@@ -1065,15 +1065,20 @@ class VPInstructionWithType : public VPInstruction {
10651065
: VPInstruction(Opcode, Operands, FMFs, DL, Name), ResultTy(ResultTy) {}
10661066

10671067
static inline bool classof(const VPRecipeBase *R) {
1068-
if (isa<VPInstruction>(R) &&
1069-
cast<VPInstruction>(R)->getOpcode() == VPInstruction::StepVector)
1070-
return true;
10711068
// VPInstructionWithType are VPInstructions with specific opcodes requiring
10721069
// type information.
10731070
if (R->isScalarCast())
10741071
return true;
10751072
auto *VPI = dyn_cast<VPInstruction>(R);
1076-
return VPI && VPI->getOpcode() == VPInstruction::WideIVStep;
1073+
if (!VPI)
1074+
return false;
1075+
switch (VPI->getOpcode()) {
1076+
case VPInstruction::WideIVStep:
1077+
case VPInstruction::StepVector:
1078+
return true;
1079+
default:
1080+
return false;
1081+
}
10771082
}
10781083

10791084
static inline bool classof(const VPUser *R) {
@@ -1833,6 +1838,8 @@ class VPWidenInductionRecipe : public VPHeaderPHIRecipe {
18331838
class VPWidenIntOrFpInductionRecipe : public VPWidenInductionRecipe {
18341839
TruncInst *Trunc;
18351840

1841+
bool isUnrolled() const { return getNumOperands() == 6; }
1842+
18361843
public:
18371844
VPWidenIntOrFpInductionRecipe(PHINode *IV, VPValue *Start, VPValue *Step,
18381845
VPValue *VF, const InductionDescriptor &IndDesc,
@@ -1913,9 +1920,6 @@ class VPWidenIntOrFpInductionRecipe : public VPWidenInductionRecipe {
19131920
VPValue *getLastUnrolledPartOperand() {
19141921
return isUnrolled() ? getOperand(getNumOperands() - 1) : this;
19151922
}
1916-
1917-
private:
1918-
bool isUnrolled() const { return getNumOperands() == 6; }
19191923
};
19201924

19211925
class VPWidenPointerInductionRecipe : public VPWidenInductionRecipe,

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1966,7 +1966,8 @@ void VPWidenIntOrFpInductionRecipe::execute(VPTransformState &State) {
19661966

19671967
Value *SplatStart = Builder.CreateVectorSplat(State.VF, Start);
19681968
assert(cast<VPInstruction>(getStepVector())->getOpcode() ==
1969-
VPInstruction::StepVector);
1969+
VPInstruction::StepVector &&
1970+
"step vector operand must be a StepVector");
19701971
Value *SteppedStart =
19711972
::getStepVector(SplatStart, Step, State.get(getStepVector()),
19721973
ID.getInductionOpcode(), State.VF, State.Builder);

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -2419,10 +2419,10 @@ void VPlanTransforms::convertToConcreteRecipes(VPlan &Plan,
24192419
Ty = Trunc->getType();
24202420
if (Ty->isFloatingPointTy())
24212421
Ty = IntegerType::get(Ty->getContext(), Ty->getScalarSizeInBits());
2422-
VPInstruction *StepVector = new VPInstructionWithType(
2423-
VPInstruction::StepVector, {}, Ty, R.getDebugLoc());
24242422

2425-
Plan.getVectorPreheader()->appendRecipe(StepVector);
2423+
VPBuilder Builder(Plan.getVectorPreheader());
2424+
VPInstruction *StepVector = Builder.createNaryOp(
2425+
VPInstruction::StepVector, {}, Ty, {}, R.getDebugLoc());
24262426
IVR->setStepVector(StepVector);
24272427
continue;
24282428
}

0 commit comments

Comments
 (0)