Skip to content

Commit cafad2b

Browse files
ro-iarsenm
andauthored
[AMDGPU] Add verification for amdgcn.init.exec.from.input (llvm#128172)
Check that the input register is an inreg argument to the parent function. (See the comment in `IntrinsicsAMDGPU.td`.) This LLVM defect was identified via the AMD Fuzzing project. --------- Co-authored-by: Matt Arsenault <[email protected]>
1 parent 72791fe commit cafad2b

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

llvm/lib/IR/Verifier.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6371,6 +6371,14 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
63716371
"llvm.amdgcn.cs.chain must be followed by unreachable", &Call);
63726372
break;
63736373
}
6374+
case Intrinsic::amdgcn_init_exec_from_input: {
6375+
const Argument *Arg = dyn_cast<Argument>(Call.getOperand(0));
6376+
Check(Arg && Arg->hasInRegAttr(),
6377+
"only inreg arguments to the parent function are valid as inputs to "
6378+
"this intrinsic",
6379+
&Call);
6380+
break;
6381+
}
63746382
case Intrinsic::amdgcn_set_inactive_chain_arg: {
63756383
auto CallerCC = Call.getCaller()->getCallingConv();
63766384
switch (CallerCC) {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; RUN: not llvm-as -disable-output 2>&1 %s | FileCheck %s
2+
3+
declare void @llvm.amdgcn.init.exec.from.input(i32, i32 immarg)
4+
5+
; CHECK: only inreg arguments to the parent function are valid as inputs to this intrinsic
6+
; CHECK-NEXT: call void @llvm.amdgcn.init.exec.from.input(i32 0, i32 0)
7+
define void @init_exec_from_input_fail_constant() {
8+
call void @llvm.amdgcn.init.exec.from.input(i32 0, i32 0)
9+
ret void
10+
}
11+
12+
; CHECK: only inreg arguments to the parent function are valid as inputs to this intrinsic
13+
; CHECK-NEXT: call void @llvm.amdgcn.init.exec.from.input(i32 %b, i32 0)
14+
define void @init_exec_from_input_fail_not_inreg(i32 inreg %a, i32 %b) {
15+
call void @llvm.amdgcn.init.exec.from.input(i32 %b, i32 0)
16+
ret void
17+
}
18+
19+
; CHECK: only inreg arguments to the parent function are valid as inputs to this intrinsic
20+
; CHECK-NEXT: call void @llvm.amdgcn.init.exec.from.input(i32 %c, i32 0)
21+
define void @init_exec_from_input_fail_instruction(i32 inreg %a, i32 %b) {
22+
%c = add i32 %a, %b
23+
call void @llvm.amdgcn.init.exec.from.input(i32 %c, i32 0)
24+
ret void
25+
}

0 commit comments

Comments
 (0)