Skip to content

Commit 0768068

Browse files
authored
[VPlan] Remove ExtractLastLane for plans with scalar VFs. (#171145)
ExtractLastLane is a no-op for scalar VFs. Update simplifyRecipe to remove them. This also requires adjusting the code in VPlanUnroll.cpp to split off handling of ExtractLastLane/ExtractPenultimateElement for scalar VFs, which now needs to match ExtractLastPart. PR: #171145
1 parent 7675fc7 commit 0768068

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,12 +1385,16 @@ static void simplifyRecipe(VPSingleDefRecipe *Def, VPTypeAnalysis &TypeInfo) {
13851385
return;
13861386
}
13871387

1388-
// Look through ExtractLastLane (BuildVector ....).
1389-
if (match(Def, m_ExtractLastLane(m_BuildVector()))) {
1390-
auto *BuildVector = cast<VPInstruction>(Def->getOperand(0));
1391-
Def->replaceAllUsesWith(
1392-
BuildVector->getOperand(BuildVector->getNumOperands() - 1));
1393-
return;
1388+
// Look through ExtractLastLane.
1389+
if (match(Def, m_ExtractLastLane(m_VPValue(A)))) {
1390+
if (match(A, m_BuildVector())) {
1391+
auto *BuildVector = cast<VPInstruction>(A);
1392+
Def->replaceAllUsesWith(
1393+
BuildVector->getOperand(BuildVector->getNumOperands() - 1));
1394+
return;
1395+
}
1396+
if (Plan->hasScalarVFOnly())
1397+
return Def->replaceAllUsesWith(A);
13941398
}
13951399

13961400
// Look through ExtractPenultimateElement (BuildVector ....).

llvm/lib/Transforms/Vectorize/VPlanUnroll.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,9 @@ void UnrollState::unrollBlock(VPBlockBase *VPB) {
371371
continue;
372372
}
373373

374-
if (match(&R, m_ExtractLastLaneOfLastPart(m_VPValue(Op0))) ||
375-
match(&R, m_ExtractPenultimateElement(m_VPValue(Op0)))) {
376-
addUniformForAllParts(cast<VPSingleDefRecipe>(&R));
377-
if (Plan.hasScalarVFOnly()) {
374+
if (Plan.hasScalarVFOnly()) {
375+
if (match(&R, m_ExtractLastPart(m_VPValue(Op0))) ||
376+
match(&R, m_ExtractPenultimateElement(m_VPValue(Op0)))) {
378377
auto *I = cast<VPInstruction>(&R);
379378
bool IsPenultimatePart =
380379
I->getOpcode() == VPInstruction::ExtractPenultimateElement;
@@ -383,7 +382,10 @@ void UnrollState::unrollBlock(VPBlockBase *VPB) {
383382
I->replaceAllUsesWith(getValueForPart(Op0, PartIdx));
384383
continue;
385384
}
386-
// For vector VF, always extract from the last part.
385+
}
386+
if (match(&R, m_ExtractLastLaneOfLastPart(m_VPValue(Op0))) ||
387+
match(&R, m_ExtractPenultimateElement(m_VPValue(Op0)))) {
388+
addUniformForAllParts(cast<VPSingleDefRecipe>(&R));
387389
R.setOperand(0, getValueForPart(Op0, UF - 1));
388390
continue;
389391
}

llvm/test/Transforms/LoopVectorize/interleave-and-scalarize-only.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ exit:
220220
; DBG-EMPTY:
221221
; DBG-NEXT: middle.block:
222222
; DBG-NEXT: EMIT vp<[[RESUME_1_PART:%.+]]> = extract-last-part vp<[[SCALAR_STEPS]]>
223-
; DBG-NEXT: EMIT vp<[[RESUME_1:%.+]]> = extract-last-lane vp<[[RESUME_1_PART]]>
224223
; DBG-NEXT: EMIT vp<[[CMP:%.+]]> = icmp eq vp<[[TC]]>, vp<[[VEC_TC]]>
225224
; DBG-NEXT: EMIT branch-on-cond vp<[[CMP]]>
226225
; DBG-NEXT: Successor(s): ir-bb<exit>, scalar.ph
@@ -230,7 +229,7 @@ exit:
230229
; DBG-EMPTY:
231230
; DBG-NEXT: scalar.ph:
232231
; DBG-NEXT: EMIT-SCALAR vp<[[RESUME_IV:%.+]]> = phi [ vp<[[VTC]]>, middle.block ], [ ir<0>, ir-bb<entry> ]
233-
; DBG-NEXT: EMIT-SCALAR vp<[[RESUME_P:%.*]]> = phi [ vp<[[RESUME_1]]>, middle.block ], [ ir<0>, ir-bb<entry> ]
232+
; DBG-NEXT: EMIT-SCALAR vp<[[RESUME_P:%.*]]> = phi [ vp<[[RESUME_1_PART]]>, middle.block ], [ ir<0>, ir-bb<entry> ]
234233
; DBG-NEXT: Successor(s): ir-bb<loop>
235234
; DBG-EMPTY:
236235
; DBG-NEXT: ir-bb<loop>:

0 commit comments

Comments
 (0)