Skip to content

Commit fe36dfe

Browse files
committed
[VPlan] Verify scalar types in VPlanVerifier. NFCI
VTypeAnalysis contains some assertions which can be useful for reasoning that the types of various operands match. This patch teaches VPlanVerifier to invoke VTypeAnalysis to check them, and catches some issues with VPInstruction types that are also fixed here: * Handles the missing cases for CalculateTripCountMinusVF, CanonicalIVIncrementForPart and AnyOf * Fixes LogicalAnd to return its operands' type (to align with `and` in the LangRef) * Fixes ICmp and ActiveLaneMask to return i1 (to align with `icmp` and `@llvm.get.active.lane.mask` in the LangRef)
1 parent ffe5cdd commit fe36dfe

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPInstruction *R) {
6060
}
6161
case Instruction::ICmp:
6262
case VPInstruction::ActiveLaneMask:
63-
return inferScalarType(R->getOperand(1));
63+
assert(inferScalarType(R->getOperand(0)) ==
64+
inferScalarType(R->getOperand(1)) &&
65+
"different types inferred for different operands");
66+
return IntegerType::get(Ctx, 1);
6467
case VPInstruction::ComputeReductionResult: {
6568
auto *PhiR = cast<VPReductionPHIRecipe>(R->getOperand(0));
6669
auto *OrigPhi = cast<PHINode>(PhiR->getUnderlyingValue());
@@ -71,15 +74,17 @@ Type *VPTypeAnalysis::inferScalarTypeForRecipe(const VPInstruction *R) {
7174
case VPInstruction::FirstOrderRecurrenceSplice:
7275
case VPInstruction::Not:
7376
case VPInstruction::ResumePhi:
77+
case VPInstruction::CalculateTripCountMinusVF:
78+
case VPInstruction::CanonicalIVIncrementForPart:
79+
case VPInstruction::AnyOf:
80+
case VPInstruction::LogicalAnd:
7481
return SetResultTyFromOp();
7582
case VPInstruction::ExtractFromEnd: {
7683
Type *BaseTy = inferScalarType(R->getOperand(0));
7784
if (auto *VecTy = dyn_cast<VectorType>(BaseTy))
7885
return VecTy->getElementType();
7986
return BaseTy;
8087
}
81-
case VPInstruction::LogicalAnd:
82-
return IntegerType::get(Ctx, 1);
8388
case VPInstruction::PtrAdd:
8489
// Return the type based on the pointer argument (i.e. first operand).
8590
return inferScalarType(R->getOperand(0));

llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ using namespace llvm;
2626
namespace {
2727
class VPlanVerifier {
2828
const VPDominatorTree &VPDT;
29+
VPTypeAnalysis &TypeInfo;
2930

3031
SmallPtrSet<BasicBlock *, 8> WrappedIRBBs;
3132

@@ -58,7 +59,8 @@ class VPlanVerifier {
5859
bool verifyRegionRec(const VPRegionBlock *Region);
5960

6061
public:
61-
VPlanVerifier(VPDominatorTree &VPDT) : VPDT(VPDT) {}
62+
VPlanVerifier(VPDominatorTree &VPDT, VPTypeAnalysis &TypeInfo)
63+
: VPDT(VPDT), TypeInfo(TypeInfo) {}
6264

6365
bool verify(const VPlan &Plan);
6466
};
@@ -195,6 +197,9 @@ bool VPlanVerifier::verifyVPBasicBlock(const VPBasicBlock *VPBB) {
195197
return false;
196198
}
197199
for (const VPValue *V : R.definedValues()) {
200+
// Verify that recipes' operands have matching types.
201+
TypeInfo.inferScalarType(V);
202+
198203
for (const VPUser *U : V->users()) {
199204
auto *UI = dyn_cast<VPRecipeBase>(U);
200205
// TODO: check dominance of incoming values for phis properly.
@@ -406,6 +411,8 @@ bool VPlanVerifier::verify(const VPlan &Plan) {
406411
bool llvm::verifyVPlanIsValid(const VPlan &Plan) {
407412
VPDominatorTree VPDT;
408413
VPDT.recalculate(const_cast<VPlan &>(Plan));
409-
VPlanVerifier Verifier(VPDT);
414+
VPTypeAnalysis TypeInfo(
415+
const_cast<VPlan &>(Plan).getCanonicalIV()->getScalarType());
416+
VPlanVerifier Verifier(VPDT, TypeInfo);
410417
return Verifier.verify(Plan);
411418
}

0 commit comments

Comments
 (0)