Skip to content

Commit e30399e

Browse files
committed
[AMDGPU] Add argument range annotations to intrinsics where applicable
This commit adds annotations to AMDGPU intrinscis that take arguments which are documented to lie within a specified range, ensuring that invalid instances of these intrinsics don't pass verification. (Note that certain intrinsics that could have range annothations don't, as their existing behavior is to clame out-of-range values silently.)
1 parent 2e2fe68 commit e30399e

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

llvm/include/llvm/IR/IntrinsicsAMDGPU.td

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -653,19 +653,20 @@ def int_amdgcn_cvt_pk_bf8_f16
653653
// byte_sel selects byte to write in vdst.
654654
def int_amdgcn_cvt_sr_fp8_f16 : DefaultAttrsIntrinsic<
655655
[llvm_i32_ty], [llvm_half_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
656-
[IntrNoMem, IntrSpeculatable, ImmArg<ArgIndex<3>>]
656+
[IntrNoMem, IntrSpeculatable, ImmArg<ArgIndex<3>>, Range<ArgIndex<3>, 0, 4>]
657657
>, ClangBuiltin<"__builtin_amdgcn_cvt_sr_fp8_f16">;
658658

659659
// llvm.amdgcn.cvt.sr.bf8.f16 i32 vdst, half src, i32 seed, i32 old, imm byte_sel [0..3]
660660
// byte_sel selects byte to write in vdst.
661661
def int_amdgcn_cvt_sr_bf8_f16 : DefaultAttrsIntrinsic<
662662
[llvm_i32_ty], [llvm_half_ty, llvm_i32_ty, llvm_i32_ty, llvm_i32_ty],
663-
[IntrNoMem, IntrSpeculatable, ImmArg<ArgIndex<3>>]
663+
[IntrNoMem, IntrSpeculatable, ImmArg<ArgIndex<3>>, Range<ArgIndex<3>, 0, 4>]
664664
>, ClangBuiltin<"__builtin_amdgcn_cvt_sr_bf8_f16">;
665665

666666
// llvm.amdgcn.cvt.scale.pk32.f16.bf6 v32f16 vdst, v6i32 src0, i32 scale_sel [0..15]
667667
class AMDGPUCvtScaleIntrinsic<LLVMType DstTy, LLVMType Src0Ty, string name> : DefaultAttrsIntrinsic<
668-
[DstTy], [Src0Ty, llvm_i32_ty, llvm_i32_ty], [IntrNoMem, IntrSpeculatable, ImmArg<ArgIndex<2>>]
668+
[DstTy], [Src0Ty, llvm_i32_ty, llvm_i32_ty],
669+
[IntrNoMem, IntrSpeculatable, ImmArg<ArgIndex<2>>, Range<ArgIndex<2>, 0, 16>]
669670
>, ClangBuiltin<"__builtin_amdgcn_"#name>;
670671

671672
class AMDGPUCvtScaleF32Intrinsic<LLVMType DstTy, LLVMType Src0Ty, string name> : DefaultAttrsIntrinsic<
@@ -746,7 +747,8 @@ class AMDGPUCvtScaleFP4FP8BF8ToF1632Intrinsic<LLVMType DstTy, string name> : Def
746747
[llvm_i32_ty, // src
747748
llvm_float_ty, // scale
748749
llvm_i32_ty], // src_sel index [0..3]
749-
[IntrNoMem, ImmArg<ArgIndex<2>>]
750+
[IntrNoMem,
751+
ImmArg<ArgIndex<2>>, Range<ArgIndex<2>, 0, 4>]
750752
>, ClangBuiltin<"__builtin_amdgcn_"#name>;
751753

752754
class AMDGPUCvtScale_pk_FromFP8BF8Intrinsic<LLVMType DstTy, string name> : DefaultAttrsIntrinsic<
@@ -783,7 +785,7 @@ class AMDGPUCvtScaleFP8BF8ToF16TiedInputIntrinsic<LLVMType DstTy, string name> :
783785
llvm_float_ty, // scale
784786
llvm_i32_ty, // src_sel_index[0..3]
785787
llvm_i1_ty], // dst_lo_hi_sel[true false]
786-
[IntrNoMem, ImmArg<ArgIndex<3>>, ImmArg<ArgIndex<4>>]
788+
[IntrNoMem, ImmArg<ArgIndex<3>>, Range<ArgIndex<3>, 0, 4>, ImmArg<ArgIndex<4>>]
787789
>, ClangBuiltin<"__builtin_amdgcn_"#name>;
788790

789791
class AMDGPUCvtScaleF32ToFP4Intrinsic<string name> : DefaultAttrsIntrinsic<
@@ -793,7 +795,7 @@ class AMDGPUCvtScaleF32ToFP4Intrinsic<string name> : DefaultAttrsIntrinsic<
793795
llvm_float_ty, // src1
794796
llvm_float_ty, // scale
795797
llvm_i32_ty], // dst_sel_index[0..3]
796-
[IntrNoMem, ImmArg<ArgIndex<4>>]
798+
[IntrNoMem, ImmArg<ArgIndex<4>>, Range<ArgIndex<4>, 0, 4>]
797799
>, ClangBuiltin<"__builtin_amdgcn_"#name>;
798800

799801
class AMDGPUCvtScaleF16ToFP4TiedInputIntrinsic<LLVMType SrcTy, string name> : DefaultAttrsIntrinsic<
@@ -802,7 +804,7 @@ class AMDGPUCvtScaleF16ToFP4TiedInputIntrinsic<LLVMType SrcTy, string name> : De
802804
SrcTy, // src
803805
llvm_float_ty, // scale
804806
llvm_i32_ty], // dest_sel_index [0..3]
805-
[IntrNoMem, ImmArg<ArgIndex<3>>]
807+
[IntrNoMem, ImmArg<ArgIndex<3>>, Range<ArgIndex<3>, 0, 4>]
806808
>, ClangBuiltin<"__builtin_amdgcn_"#name>;
807809

808810
class AMDGPUCvtScaleBF16F16F32SRToFP4BF8F8TiedInputIntrinsic<LLVMType Src0Ty, string name> : DefaultAttrsIntrinsic<
@@ -812,7 +814,7 @@ class AMDGPUCvtScaleBF16F16F32SRToFP4BF8F8TiedInputIntrinsic<LLVMType Src0Ty, st
812814
llvm_i32_ty, // seed
813815
llvm_float_ty, // scale
814816
llvm_i32_ty], // dst_sel_index[0..3]
815-
[IntrNoMem, ImmArg<ArgIndex<4>>]
817+
[IntrNoMem, ImmArg<ArgIndex<4>>, Range<ArgIndex<4>, 0, 4>]
816818
>, ClangBuiltin<"__builtin_amdgcn_"#name>;
817819

818820
class AMDGPUCvtScaleSRF32ToBF16F16TiedInputIntrinsic<LLVMType DstTy, string name> : DefaultAttrsIntrinsic<

0 commit comments

Comments
 (0)