Skip to content

AMDGPU: Add basic verification for mfma scale intrinsics #117048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions llvm/include/llvm/IR/IntrinsicsAMDGPU.td
Original file line number Diff line number Diff line change
Expand Up @@ -2973,12 +2973,10 @@ class AMDGPUMfmaIntrinsic<LLVMType DestTy, LLVMType SrcABTy> :
// blgp.
//
// These should be <8 x i32> for f8 formats, <6 x i32> for f6 formats,
// and <4 x i32> for f4 formats. If the format control bits imply a
// smaller type than used, the high elements will be truncated.
//
// If the format control bits imply a larger type than used, the high
// elements are padded with undef.

// and <4 x i32> for f4 formats. It is invalid to use a format that
// requires more registers than the corresponding vector type (e.g. it
// is illegal to use <6 x i32> in operand 0 if cbsz specifies an f8
// format that requires 8 registers).
class AMDGPUMfmaScaleIntrinsic<LLVMType DestTy> :
DefaultAttrsIntrinsic<[DestTy],
[llvm_anyvector_ty, llvm_anyvector_ty, DestTy,
Expand Down
49 changes: 49 additions & 0 deletions llvm/lib/IR/Verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6383,6 +6383,55 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
"llvm.amdgcn.s.prefetch.data only supports global or constant memory");
break;
}
case Intrinsic::amdgcn_mfma_scale_f32_16x16x128_f8f6f4:
case Intrinsic::amdgcn_mfma_scale_f32_32x32x64_f8f6f4: {
Value *Src0 = Call.getArgOperand(0);
Value *Src1 = Call.getArgOperand(1);

uint64_t CBSZ = cast<ConstantInt>(Call.getArgOperand(3))->getZExtValue();
uint64_t BLGP = cast<ConstantInt>(Call.getArgOperand(4))->getZExtValue();
Check(CBSZ <= 4, "invalid value for cbsz format", Call,
Call.getArgOperand(3));
Check(BLGP <= 4, "invalid value for blgp format", Call,
Call.getArgOperand(4));

// AMDGPU::MFMAScaleFormats values
auto getFormatNumRegs = [](unsigned FormatVal) {
switch (FormatVal) {
case 0:
case 1:
return 8u;
case 2:
case 3:
return 6u;
case 4:
return 4u;
default:
llvm_unreachable("invalid format value");
}
};

auto isValidSrcASrcBVector = [](FixedVectorType *Ty) {
if (!Ty || !Ty->getElementType()->isIntegerTy(32))
return false;
unsigned NumElts = Ty->getNumElements();
return NumElts == 4 || NumElts == 6 || NumElts == 8;
};

auto *Src0Ty = dyn_cast<FixedVectorType>(Src0->getType());
auto *Src1Ty = dyn_cast<FixedVectorType>(Src1->getType());
Check(isValidSrcASrcBVector(Src0Ty),
"operand 0 must be 4, 6 or 8 element i32 vector", &Call, Src0);
Check(isValidSrcASrcBVector(Src1Ty),
"operand 1 must be 4, 6 or 8 element i32 vector", &Call, Src1);

// Permit excess registers for the format.
Check(Src0Ty->getNumElements() >= getFormatNumRegs(CBSZ),
"invalid vector type for format", &Call, Src0, Call.getArgOperand(3));
Check(Src1Ty->getNumElements() >= getFormatNumRegs(BLGP),
"invalid vector type for format", &Call, Src1, Call.getArgOperand(5));
break;
}
case Intrinsic::nvvm_setmaxnreg_inc_sync_aligned_u32:
case Intrinsic::nvvm_setmaxnreg_dec_sync_aligned_u32: {
Value *V = Call.getArgOperand(0);
Expand Down
Loading
Loading