Skip to content

Commit af491b4

Browse files
committed
!fixup address latest comments, thanks!
1 parent 4a8d4da commit af491b4

File tree

5 files changed

+16
-17
lines changed

5 files changed

+16
-17
lines changed

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,19 +1004,15 @@ void VPlan::execute(VPTransformState *State) {
10041004
Inc->setOperand(0, State->get(IV->getLastUnrolledPartOperand()));
10051005
continue;
10061006
}
1007-
if (auto *VPI = dyn_cast<VPInstruction>(&R)) {
1008-
Value *Phi = State->get(VPI, true);
1009-
Value *Val = State->get(VPI->getOperand(1), true);
1010-
cast<PHINode>(Phi)->addIncoming(Val, VectorLatchBB);
1011-
continue;
1012-
}
10131007

1014-
auto *PhiR = cast<VPHeaderPHIRecipe>(&R);
1015-
bool NeedsScalar =
1008+
auto *PhiR = cast<VPSingleDefRecipe>(&R);
1009+
// VPInstructions currently model scalar Phis only.
1010+
bool NeedsScalar = isa<VPInstruction>(PhiR) ||
10161011
(isa<VPReductionPHIRecipe>(PhiR) &&
10171012
cast<VPReductionPHIRecipe>(PhiR)->isInLoop());
10181013
Value *Phi = State->get(PhiR, NeedsScalar);
1019-
Value *Val = State->get(PhiR->getBackedgeValue(), NeedsScalar);
1014+
// VPHeaderPHIRecipe supports getBackedgeValue() but VPInstruction does not.
1015+
Value *Val = State->get(PhiR->getOperand(1), NeedsScalar);
10201016
cast<PHINode>(Phi)->addIncoming(Val, VectorLatchBB);
10211017
}
10221018
}

llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPInstruction *R) {
7272
case VPInstruction::ExplicitVectorLength:
7373
return Type::getIntNTy(Ctx, 32);
7474
case Instruction::PHI:
75-
// Avoid inferring the type for other operands, as this may lead to infinite
76-
// recursions for cycles.
75+
// Infer the type of first operand only, as other operands of header phi's
76+
// may lead to infinite recursion.
7777
return inferScalarType(R->getOperand(0));
7878
case VPInstruction::FirstOrderRecurrenceSplice:
7979
case VPInstruction::Not:

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,8 @@ bool VPInstruction::canGenerateScalarForFirstLane() const {
422422
if (isSingleScalar() || isVectorToScalar())
423423
return true;
424424
switch (Opcode) {
425-
case Instruction::PHI:
426425
case Instruction::ICmp:
426+
case Instruction::PHI:
427427
case Instruction::Select:
428428
case VPInstruction::BranchOnCond:
429429
case VPInstruction::BranchOnCount:
@@ -464,6 +464,7 @@ Value *VPInstruction::generate(VPTransformState &State) {
464464

465465
switch (getOpcode()) {
466466
case Instruction::PHI: {
467+
// At the moment, VPInstructions with PHI opcodes are only user for scalar header phis.
467468
BasicBlock *VectorPH = State.CFG.getPreheaderBBFor(this);
468469
Value *Start = State.get(getOperand(0), VPLane(0));
469470
PHINode *Phi = State.Builder.CreatePHI(Start->getType(), 2, Name);
@@ -784,7 +785,7 @@ bool VPInstruction::isVectorToScalar() const {
784785
}
785786

786787
bool VPInstruction::isSingleScalar() const {
787-
return getOpcode() == VPInstruction::ResumePhi;
788+
return getOpcode() == VPInstruction::ResumePhi || getOpcode() == Instruction::PHI;
788789
}
789790

790791
#if !defined(NDEBUG)

llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ bool VPlanVerifier::verifyPhiRecipes(const VPBasicBlock *VPBB) {
7777
if (isa<VPActiveLaneMaskPHIRecipe>(RecipeI))
7878
NumActiveLaneMaskPhiRecipes++;
7979

80-
if (IsHeaderVPBB && !isa<VPHeaderPHIRecipe, VPWidenPHIRecipe>(*RecipeI)) {
80+
if (IsHeaderVPBB && !isa<VPHeaderPHIRecipe, VPWidenPHIRecipe>(*RecipeI) && !isa<VPInstruction>(*RecipeI) && cast<VPInstruction>(RecipeI)->getOpcode() == Instruction::PHI) {
8181
errs() << "Found non-header PHI recipe in header VPBB";
8282
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
8383
errs() << ": ";
@@ -149,7 +149,7 @@ bool VPlanVerifier::verifyEVLRecipe(const VPInstruction &EVL) const {
149149
[&](const VPScalarCastRecipe *S) { return VerifyEVLUse(*S, 0); })
150150
.Case<VPInstruction>([&](const VPInstruction *I) {
151151
if (I->getOpcode() == Instruction::PHI)
152-
return VerifyEVLUse(*I, I->getNumOperands() - 1);
152+
return VerifyEVLUse(*I, 1);
153153
if (I->getOpcode() != Instruction::Add) {
154154
errs() << "EVL is used as an operand in non-VPInstruction::Add\n";
155155
return false;
@@ -209,7 +209,9 @@ bool VPlanVerifier::verifyVPBasicBlock(const VPBasicBlock *VPBB) {
209209
if (!UI ||
210210
isa<VPHeaderPHIRecipe, VPWidenPHIRecipe, VPPredInstPHIRecipe>(UI) ||
211211
(isa<VPIRInstruction>(UI) &&
212-
isa<PHINode>(cast<VPIRInstruction>(UI)->getInstruction())))
212+
isa<PHINode>(cast<VPIRInstruction>(UI)->getInstruction())) ||
213+
(isa<VPInstruction>(UI) && cast<VPInstruction>(UI)->getOpcode() == Instruction::PHI)
214+
)
213215
continue;
214216

215217
// If the user is in the same block, check it comes after R in the

llvm/test/Transforms/LoopVectorize/RISCV/vplan-vp-intrinsics-fixed-order-recurrence.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ define void @first_order_recurrence(ptr noalias %A, ptr noalias %B, i64 %TC) {
2727
; IF-EVL-NEXT: EMIT vp<[[IV:%[0-9]+]]> = CANONICAL-INDUCTION
2828
; IF-EVL-NEXT: EXPLICIT-VECTOR-LENGTH-BASED-IV-PHI vp<[[EVL_PHI:%[0-9]+]]> = phi ir<0>, vp<[[IV_NEXT:%.+]]>
2929
; IF-EVL-NEXT: FIRST-ORDER-RECURRENCE-PHI ir<[[FOR_PHI:%.+]]> = phi ir<33>, ir<[[LD:%.+]]>
30-
; IF-EVL-NEXT: SCALAR-PHI vp<[[PREV_EVL:%.+]]> = phi vp<[[VF32]]>, vp<[[EVL:%.+]]>
30+
; IF-EVL-NEXT: EMIT vp<[[PREV_EVL:%.+]]> = phi vp<[[VF32]]>, vp<[[EVL:%.+]]>
3131
; IF-EVL-NEXT: EMIT vp<[[AVL:%.+]]> = sub ir<%TC>, vp<[[EVL_PHI]]>
3232
; IF-EVL-NEXT: EMIT vp<[[EVL]]> = EXPLICIT-VECTOR-LENGTH vp<[[AVL]]>
3333
; IF-EVL-NEXT: vp<[[ST:%[0-9]+]]> = SCALAR-STEPS vp<[[EVL_PHI]]>, ir<1>

0 commit comments

Comments
 (0)