-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[VPlan] Add VPInstruction::StepVector and use it in VPWidenIntOrFpInductionRecipe #129508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
68bbf28
5d307e4
83fafe3
2b7ee27
e73e994
c7d9d75
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -930,6 +930,7 @@ bool VPInstruction::opcodeMayReadOrWriteFromMemory() const { | |
case VPInstruction::Not: | ||
case VPInstruction::PtrAdd: | ||
case VPInstruction::WideIVStep: | ||
case VPInstruction::StepVector: | ||
return false; | ||
default: | ||
return true; | ||
|
@@ -1078,8 +1079,6 @@ void VPInstruction::print(raw_ostream &O, const Twine &Indent, | |
|
||
void VPInstructionWithType::execute(VPTransformState &State) { | ||
State.setDebugLocFrom(getDebugLoc()); | ||
assert(vputils::onlyFirstLaneUsed(this) && | ||
"Codegen only implemented for first lane."); | ||
switch (getOpcode()) { | ||
case Instruction::ZExt: | ||
case Instruction::Trunc: { | ||
|
@@ -1089,6 +1088,12 @@ void VPInstructionWithType::execute(VPTransformState &State) { | |
State.set(this, Cast, VPLane(0)); | ||
break; | ||
} | ||
case VPInstruction::StepVector: { | ||
Value *StepVector = | ||
State.Builder.CreateStepVector(VectorType::get(ResultTy, State.VF)); | ||
State.set(this, StepVector); | ||
break; | ||
} | ||
default: | ||
llvm_unreachable("opcode not implemented yet"); | ||
} | ||
|
@@ -1106,6 +1111,9 @@ void VPInstructionWithType::print(raw_ostream &O, const Twine &Indent, | |
O << "wide-iv-step "; | ||
printOperands(O, SlotTracker); | ||
break; | ||
case VPInstruction::StepVector: | ||
O << "step-vector " << *ResultTy; | ||
break; | ||
default: | ||
assert(Instruction::isCast(getOpcode()) && "unhandled opcode"); | ||
O << Instruction::getOpcodeName(getOpcode()) << " "; | ||
|
@@ -1875,7 +1883,8 @@ InstructionCost VPHeaderPHIRecipe::computeCost(ElementCount VF, | |
/// (0 * Step, 1 * Step, 2 * Step, ...) | ||
/// to each vector element of Val. | ||
/// \p Opcode is relevant for FP induction variable. | ||
static Value *getStepVector(Value *Val, Value *Step, | ||
/// \p InitVec is an integer step vector from 0 with a step of 1. | ||
static Value *getStepVector(Value *Val, Value *Step, Value *InitVec, | ||
Instruction::BinaryOps BinOp, ElementCount VF, | ||
IRBuilderBase &Builder) { | ||
assert(VF.isVector() && "only vector VFs are supported"); | ||
|
@@ -1891,15 +1900,6 @@ static Value *getStepVector(Value *Val, Value *Step, | |
|
||
SmallVector<Constant *, 8> Indices; | ||
|
||
// Create a vector of consecutive numbers from zero to VF. | ||
VectorType *InitVecValVTy = ValVTy; | ||
if (STy->isFloatingPointTy()) { | ||
Type *InitVecValSTy = | ||
IntegerType::get(STy->getContext(), STy->getScalarSizeInBits()); | ||
InitVecValVTy = VectorType::get(InitVecValSTy, VLen); | ||
} | ||
Value *InitVec = Builder.CreateStepVector(InitVecValVTy); | ||
|
||
if (STy->isIntegerTy()) { | ||
Step = Builder.CreateVectorSplat(VLen, Step); | ||
assert(Step->getType() == Val->getType() && "Invalid step vec"); | ||
|
@@ -1965,8 +1965,12 @@ void VPWidenIntOrFpInductionRecipe::execute(VPTransformState &State) { | |
} | ||
|
||
Value *SplatStart = Builder.CreateVectorSplat(State.VF, Start); | ||
Value *SteppedStart = getStepVector(SplatStart, Step, ID.getInductionOpcode(), | ||
State.VF, State.Builder); | ||
assert(cast<VPInstruction>(getStepVector())->getOpcode() == | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Although that may be too restrictive, for fixed vectors it could just be a constant vector? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed vectors would still be a VPInstruction::StepVector. Hopefully the need for this assertion would also go away if we fully expand the recipe in #118638 |
||
VPInstruction::StepVector && | ||
"step vector operand must be a StepVector"); | ||
Value *SteppedStart = | ||
::getStepVector(SplatStart, Step, State.get(getStepVector()), | ||
ID.getInductionOpcode(), State.VF, State.Builder); | ||
|
||
// We create vector phi nodes for both integer and floating-point induction | ||
// variables. Here, we determine the kind of arithmetic we will perform. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need the dummy operands or can we add the operand when needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried adding the operands at the call site this again and it ends up needing a bunch more code because we have to create the step vector in both createWidenInductionRecipes and tryToConvertVPInstructionsToVPRecipes, and also we need to recreate it again in optimizeVectorInductionWidthForTCAndVFUF if the bitwidth is reduced.
It also doesn't really work well when the operand is added in
convertToConcreteRecipes
because then getLastUnrolledPartOperandand
getSplatVFValueget confused with the number of operands in
isUnrolled` .The dummy operand would hopefully only be temporary and would go away with #118638 whenever the recipe is fully expanded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see, because we expect the unrolled operand to be at a fixed index, right and we do not add the unroll part for the first part?
It seems a bit strange to add VF here though, if we need a dummy operand, would it be better to use something like poison?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh good idea, I've changed it to poison in e73e994