Skip to content

Commit d062886

Browse files
fhahnPriyanshu3820
authored andcommitted
[VPlan] Refine mayRead/WriteFromMemory for VPInst, fix VPlan SLP check.
Fix VPlan SLP check incorrectly bailing out for non-VPInstructions. Starting from the beginning of the block will include canonical IVs, which in turn are not VPInstructions. If we hit a non-VPInstruction, we should conservatively treat is as potentially unvectorizable. To keep the tests working as expected, refine mayRead/WriteFromMemory for Load and GEP VPInstructions.
1 parent fd5a47b commit d062886

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@ bool VPRecipeBase::mayWriteToMemory() const {
5050
switch (getVPDefID()) {
5151
case VPExpressionSC:
5252
return cast<VPExpressionRecipe>(this)->mayReadOrWriteMemory();
53-
case VPInstructionSC:
54-
return cast<VPInstruction>(this)->opcodeMayReadOrWriteFromMemory();
53+
case VPInstructionSC: {
54+
auto *VPI = cast<VPInstruction>(this);
55+
// Loads read from memory but don't write to memory.
56+
if (VPI->getOpcode() == Instruction::Load)
57+
return false;
58+
return VPI->opcodeMayReadOrWriteFromMemory();
59+
}
5560
case VPInterleaveEVLSC:
5661
case VPInterleaveSC:
5762
return cast<VPInterleaveBase>(this)->getNumStoreOperands() > 0;
@@ -1278,6 +1283,7 @@ bool VPInstruction::opcodeMayReadOrWriteFromMemory() const {
12781283
if (Instruction::isBinaryOp(getOpcode()) || Instruction::isCast(getOpcode()))
12791284
return false;
12801285
switch (getOpcode()) {
1286+
case Instruction::GetElementPtr:
12811287
case Instruction::ExtractElement:
12821288
case Instruction::Freeze:
12831289
case Instruction::FCmp:

llvm/lib/Transforms/Vectorize/VPlanSLP.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,10 @@ bool VPlanSlp::areVectorizable(ArrayRef<VPValue *> Operands) const {
169169
if (Opcode == Instruction::Load) {
170170
unsigned LoadsSeen = 0;
171171
VPBasicBlock *Parent = cast<VPInstruction>(Operands[0])->getParent();
172-
for (auto &I : *Parent) {
172+
for (auto &I : make_range(Parent->getFirstNonPhi(), Parent->end())) {
173173
auto *VPI = dyn_cast<VPInstruction>(&I);
174174
if (!VPI)
175-
break;
175+
return false;
176176
if (VPI->getOpcode() == Instruction::Load &&
177177
llvm::is_contained(Operands, VPI))
178178
LoadsSeen++;

0 commit comments

Comments
 (0)