Skip to content

[AMDGPU] Add verification for amdgcn.init.exec.from.input #128172

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 7 commits into from
Feb 23, 2025
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
8 changes: 8 additions & 0 deletions llvm/lib/IR/Verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6369,6 +6369,14 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
"VGPR arguments must not have the `inreg` attribute", &Call);
break;
}
case Intrinsic::amdgcn_init_exec_from_input: {
const Argument *Arg = dyn_cast<Argument>(Call.getOperand(0));
Check(Arg && Arg->hasInRegAttr(),
"only inreg arguments to the parent function are valid as inputs to "
"this intrinsic",
&Call);
break;
}
case Intrinsic::amdgcn_set_inactive_chain_arg: {
auto CallerCC = Call.getCaller()->getCallingConv();
switch (CallerCC) {
Expand Down
25 changes: 25 additions & 0 deletions llvm/test/Verifier/AMDGPU/intrinsic-amdgpu-init-exec-from-input.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
; RUN: not llvm-as -disable-output 2>&1 %s | FileCheck %s

declare void @llvm.amdgcn.init.exec.from.input(i32, i32 immarg)

; CHECK: only inreg arguments to the parent function are valid as inputs to this intrinsic
; CHECK-NEXT: call void @llvm.amdgcn.init.exec.from.input(i32 0, i32 0)
define void @init_exec_from_input_fail_constant() {
call void @llvm.amdgcn.init.exec.from.input(i32 0, i32 0)
ret void
}

; CHECK: only inreg arguments to the parent function are valid as inputs to this intrinsic
; CHECK-NEXT: call void @llvm.amdgcn.init.exec.from.input(i32 %b, i32 0)
define void @init_exec_from_input_fail_not_inreg(i32 inreg %a, i32 %b) {
call void @llvm.amdgcn.init.exec.from.input(i32 %b, i32 0)
ret void
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also test a case where it's not an argument (try one with a constant and one with an instruction)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I added another check for the case that the operand is an instruction!
Isn't the constant case covered by the first function?


; CHECK: only inreg arguments to the parent function are valid as inputs to this intrinsic
; CHECK-NEXT: call void @llvm.amdgcn.init.exec.from.input(i32 %c, i32 0)
define void @init_exec_from_input_fail_instruction(i32 inreg %a, i32 %b) {
%c = add i32 %a, %b
call void @llvm.amdgcn.init.exec.from.input(i32 %c, i32 0)
ret void
}