Skip to content

Commit 07276e4

Browse files
committed
[LV] Check VPValue operand instead of Cost::isUniformAfterVec (NFC).
ILV::scalarizeInstruction still uses the original IR operands to check if an input value is uniform after vectorization. There is no need to go back to the cost model to figure that out, as the information is already explicit in the VPlan. Just check directly whether the VPValue is defined outside the plan or is a uniform VPReplicateRecipe. Reviewed By: Ayal Differential Revision: https://reviews.llvm.org/D114253
1 parent 1f257ac commit 07276e4

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3030,14 +3030,12 @@ void InnerLoopVectorizer::scalarizeInstruction(Instruction *Instr,
30303030
Builder.GetInsertPoint());
30313031
// Replace the operands of the cloned instructions with their scalar
30323032
// equivalents in the new loop.
3033-
for (unsigned op = 0, e = RepRecipe->getNumOperands(); op != e; ++op) {
3034-
auto *Operand = dyn_cast<Instruction>(Instr->getOperand(op));
3033+
for (auto &I : enumerate(RepRecipe->operands())) {
30353034
auto InputInstance = Instance;
3036-
if (!Operand || !OrigLoop->contains(Operand) ||
3037-
(Cost->isUniformAfterVectorization(Operand, State.VF)))
3035+
VPValue *Operand = I.value();
3036+
if (State.Plan->isUniformAfterVectorization(Operand))
30383037
InputInstance.Lane = VPLane::getFirstLane();
3039-
auto *NewOp = State.get(RepRecipe->getOperand(op), InputInstance);
3040-
Cloned->setOperand(op, NewOp);
3038+
Cloned->setOperand(I.index(), State.get(Operand, InputInstance));
30413039
}
30423040
addNewMetadata(Cloned, Instr);
30433041

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,6 +2255,12 @@ class VPlan {
22552255
return map_range(Operands, Fn);
22562256
}
22572257

2258+
/// Returns true if \p VPV is uniform after vectorization.
2259+
bool isUniformAfterVectorization(VPValue *VPV) const {
2260+
auto RepR = dyn_cast_or_null<VPReplicateRecipe>(VPV->getDef());
2261+
return !VPV->getDef() || (RepR && RepR->isUniform());
2262+
}
2263+
22582264
private:
22592265
/// Add to the given dominator tree the header block and every new basic block
22602266
/// that was created between it and the latch block, inclusive.

0 commit comments

Comments
 (0)