Skip to content

Commit dda8be4

Browse files
committed
[AMDGPU] Add verification for amdgcn.init.exec.from.input
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.
1 parent 12f8ed5 commit dda8be4

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

llvm/lib/IR/Verifier.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6369,6 +6369,21 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
63696369
"VGPR arguments must not have the `inreg` attribute", &Call);
63706370
break;
63716371
}
6372+
case Intrinsic::amdgcn_init_exec_from_input: {
6373+
const Value *InputVal = Call.getOperand(0);
6374+
bool InRegArgFound = false;
6375+
for (const Argument &Arg : Call.getCaller()->args()) {
6376+
if (Arg.hasInRegAttr() && &Arg == InputVal) {
6377+
InRegArgFound = true;
6378+
break;
6379+
}
6380+
}
6381+
Check(InRegArgFound,
6382+
"only inreg arguments to the parent function are valid as inputs to "
6383+
"this intrinsic",
6384+
&Call);
6385+
break;
6386+
}
63726387
case Intrinsic::amdgcn_set_inactive_chain_arg: {
63736388
auto CallerCC = Call.getCaller()->getCallingConv();
63746389
switch (CallerCC) {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; RUN: sed -e '/^; MARK$/,$d' %s | not llc -mtriple=amdgcn -mcpu=gfx942 2>&1 | FileCheck %s
2+
; RUN: sed -e '1,/^; MARK$/d' %s | llc -mtriple=amdgcn -mcpu=gfx942 -filetype=null
3+
4+
; Function Attrs: convergent nocallback nofree nounwind willreturn
5+
declare void @llvm.amdgcn.init.exec.from.input(i32, i32 immarg) #0
6+
attributes #0 = { convergent nocallback nofree nounwind willreturn }
7+
8+
; CHECK: only inreg arguments to the parent function are valid as inputs to this intrinsic
9+
; CHECK-NEXT: call void @llvm.amdgcn.init.exec.from.input(i32 0, i32 0)
10+
define amdgpu_ps void @init_exec_from_input_fail_immarg(i32 inreg %a, i32 %b) {
11+
call void @llvm.amdgcn.init.exec.from.input(i32 0, i32 0)
12+
ret void
13+
}
14+
15+
; CHECK: only inreg arguments to the parent function are valid as inputs to this intrinsic
16+
; CHECK-NEXT: call void @llvm.amdgcn.init.exec.from.input(i32 %b, i32 0)
17+
define amdgpu_ps void @init_exec_from_input_fail_not_inreg(i32 inreg %a, i32 %b) {
18+
call void @llvm.amdgcn.init.exec.from.input(i32 %b, i32 0)
19+
ret void
20+
}
21+
22+
; MARK
23+
24+
define amdgpu_ps void @init_exec_from_input_success(i32 inreg %a, i32 %b) {
25+
call void @llvm.amdgcn.init.exec.from.input(i32 %a, i32 0)
26+
ret void
27+
}

0 commit comments

Comments
 (0)