[llvm] cafad2b - [AMDGPU] Add verification for amdgcn.init.exec.from.input (#128172)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 23 07:42:34 PST 2025
Author: Robert Imschweiler
Date: 2025-02-23T10:42:31-05:00
New Revision: cafad2b75a6e1c4957db1967cadeb002339887e3
URL: https://github.com/llvm/llvm-project/commit/cafad2b75a6e1c4957db1967cadeb002339887e3
DIFF: https://github.com/llvm/llvm-project/commit/cafad2b75a6e1c4957db1967cadeb002339887e3.diff
LOG: [AMDGPU] Add verification for amdgcn.init.exec.from.input (#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 <arsenm2 at gmail.com>
Added:
llvm/test/Verifier/AMDGPU/intrinsic-amdgpu-init-exec-from-input.ll
Modified:
llvm/lib/IR/Verifier.cpp
Removed:
################################################################################
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 58fd575e6e7e8..310a6735d55d6 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -6371,6 +6371,14 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
"llvm.amdgcn.cs.chain must be followed by unreachable", &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) {
diff --git a/llvm/test/Verifier/AMDGPU/intrinsic-amdgpu-init-exec-from-input.ll b/llvm/test/Verifier/AMDGPU/intrinsic-amdgpu-init-exec-from-input.ll
new file mode 100644
index 0000000000000..11426041924e4
--- /dev/null
+++ b/llvm/test/Verifier/AMDGPU/intrinsic-amdgpu-init-exec-from-input.ll
@@ -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
+}
+
+; 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
+}
More information about the llvm-commits
mailing list