Skip to content

Commit 5909139

Browse files
committed
[VPlan] Simplify and unify code in verifyEVLRecipe using all_of. (NFCI)
Use all_of instead of explicit loop to reduce indentation, also properly check VPScalarCastRecipe operand.
1 parent 1e31a45 commit 5909139

File tree

1 file changed

+37
-46
lines changed

1 file changed

+37
-46
lines changed

llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp

Lines changed: 37 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -134,52 +134,43 @@ bool VPlanVerifier::verifyEVLRecipe(const VPInstruction &EVL) const {
134134
}
135135
return true;
136136
};
137-
for (const VPUser *U : EVL.users()) {
138-
if (!TypeSwitch<const VPUser *, bool>(U)
139-
.Case<VPWidenIntrinsicRecipe>(
140-
[&](const VPWidenIntrinsicRecipe *S) {
141-
return VerifyEVLUse(*S, S->getNumOperands() - 1);
142-
})
143-
.Case<VPWidenStoreEVLRecipe>([&](const VPWidenStoreEVLRecipe *S) {
144-
return VerifyEVLUse(*S, 2);
145-
})
146-
.Case<VPWidenLoadEVLRecipe, VPReverseVectorPointerRecipe>(
147-
[&](const VPRecipeBase *R) { return VerifyEVLUse(*R, 1); })
148-
.Case<VPWidenEVLRecipe>([&](const VPWidenEVLRecipe *W) {
149-
return VerifyEVLUse(
150-
*W, Instruction::isUnaryOp(W->getOpcode()) ? 1 : 2);
151-
})
152-
.Case<VPReductionEVLRecipe>([&](const VPReductionEVLRecipe *R) {
153-
return VerifyEVLUse(*R, 2);
154-
})
155-
.Case<VPScalarCastRecipe>(
156-
[&](const VPScalarCastRecipe *S) { return true; })
157-
.Case<VPInstruction>([&](const VPInstruction *I) {
158-
if (I->getOpcode() != Instruction::Add) {
159-
errs()
160-
<< "EVL is used as an operand in non-VPInstruction::Add\n";
161-
return false;
162-
}
163-
if (I->getNumUsers() != 1) {
164-
errs() << "EVL is used in VPInstruction:Add with multiple "
165-
"users\n";
166-
return false;
167-
}
168-
if (!isa<VPEVLBasedIVPHIRecipe>(*I->users().begin())) {
169-
errs() << "Result of VPInstruction::Add with EVL operand is "
170-
"not used by VPEVLBasedIVPHIRecipe\n";
171-
return false;
172-
}
173-
return true;
174-
})
175-
.Default([&](const VPUser *U) {
176-
errs() << "EVL has unexpected user\n";
177-
return false;
178-
})) {
179-
return false;
180-
}
181-
}
182-
return true;
137+
return all_of(EVL.users(), [&VerifyEVLUse](VPUser *U) {
138+
return TypeSwitch<const VPUser *, bool>(U)
139+
.Case<VPWidenIntrinsicRecipe>([&](const VPWidenIntrinsicRecipe *S) {
140+
return VerifyEVLUse(*S, S->getNumOperands() - 1);
141+
})
142+
.Case<VPWidenStoreEVLRecipe, VPReductionEVLRecipe>(
143+
[&](const VPRecipeBase *S) { return VerifyEVLUse(*S, 2); })
144+
.Case<VPWidenLoadEVLRecipe, VPReverseVectorPointerRecipe>(
145+
[&](const VPRecipeBase *R) { return VerifyEVLUse(*R, 1); })
146+
.Case<VPWidenEVLRecipe>([&](const VPWidenEVLRecipe *W) {
147+
return VerifyEVLUse(*W,
148+
Instruction::isUnaryOp(W->getOpcode()) ? 1 : 2);
149+
})
150+
.Case<VPScalarCastRecipe>(
151+
[&](const VPScalarCastRecipe *S) { return VerifyEVLUse(*S, 0); })
152+
.Case<VPInstruction>([&](const VPInstruction *I) {
153+
if (I->getOpcode() != Instruction::Add) {
154+
errs() << "EVL is used as an operand in non-VPInstruction::Add\n";
155+
return false;
156+
}
157+
if (I->getNumUsers() != 1) {
158+
errs() << "EVL is used in VPInstruction:Add with multiple "
159+
"users\n";
160+
return false;
161+
}
162+
if (!isa<VPEVLBasedIVPHIRecipe>(*I->users().begin())) {
163+
errs() << "Result of VPInstruction::Add with EVL operand is "
164+
"not used by VPEVLBasedIVPHIRecipe\n";
165+
return false;
166+
}
167+
return true;
168+
})
169+
.Default([&](const VPUser *U) {
170+
errs() << "EVL has unexpected user\n";
171+
return false;
172+
});
173+
});
183174
}
184175

185176
bool VPlanVerifier::verifyVPBasicBlock(const VPBasicBlock *VPBB) {

0 commit comments

Comments
 (0)