[llvm] fd8adf3 - [IR] Use immarg for preallocated intrinsics (NFC) (#155835)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 29 00:14:36 PDT 2025
Author: Nikita Popov
Date: 2025-09-29T09:14:33+02:00
New Revision: fd8adf3ccf7dd388e60bced617731aa82b7c145a
URL: https://github.com/llvm/llvm-project/commit/fd8adf3ccf7dd388e60bced617731aa82b7c145a
DIFF: https://github.com/llvm/llvm-project/commit/fd8adf3ccf7dd388e60bced617731aa82b7c145a.diff
LOG: [IR] Use immarg for preallocated intrinsics (NFC) (#155835)
Mark the attributes as immarg to indicate that they require a constant
integer. This was previously enforced with a manual verifier check.
Added:
Modified:
llvm/include/llvm/IR/Intrinsics.td
llvm/lib/IR/Verifier.cpp
llvm/test/Verifier/preallocated-invalid.ll
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/Intrinsics.td b/llvm/include/llvm/IR/Intrinsics.td
index 3c4ed946b98d0..96da698538314 100644
--- a/llvm/include/llvm/IR/Intrinsics.td
+++ b/llvm/include/llvm/IR/Intrinsics.td
@@ -960,8 +960,12 @@ def int_instrprof_mcdc_tvbitmap_update : Intrinsic<[],
[llvm_ptr_ty, llvm_i64_ty,
llvm_i32_ty, llvm_ptr_ty]>;
-def int_call_preallocated_setup : DefaultAttrsIntrinsic<[llvm_token_ty], [llvm_i32_ty]>;
-def int_call_preallocated_arg : DefaultAttrsIntrinsic<[llvm_ptr_ty], [llvm_token_ty, llvm_i32_ty]>;
+def int_call_preallocated_setup
+ : DefaultAttrsIntrinsic<[llvm_token_ty], [llvm_i32_ty],
+ [ImmArg<ArgIndex<0>>]>;
+def int_call_preallocated_arg
+ : DefaultAttrsIntrinsic<[llvm_ptr_ty], [llvm_token_ty, llvm_i32_ty],
+ [ImmArg<ArgIndex<1>>]>;
def int_call_preallocated_teardown : DefaultAttrsIntrinsic<[], [llvm_token_ty]>;
// This intrinsic is intentionally undocumented and users shouldn't call it;
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index b2e76cc7a8a90..8c03d6f809d50 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5869,9 +5869,7 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
break;
}
case Intrinsic::call_preallocated_setup: {
- auto *NumArgs = dyn_cast<ConstantInt>(Call.getArgOperand(0));
- Check(NumArgs != nullptr,
- "llvm.call.preallocated.setup argument must be a constant");
+ auto *NumArgs = cast<ConstantInt>(Call.getArgOperand(0));
bool FoundCall = false;
for (User *U : Call.users()) {
auto *UseCall = dyn_cast<CallBase>(U);
diff --git a/llvm/test/Verifier/preallocated-invalid.ll b/llvm/test/Verifier/preallocated-invalid.ll
index 38ed1067c497d..2c5aff231e1bd 100644
--- a/llvm/test/Verifier/preallocated-invalid.ll
+++ b/llvm/test/Verifier/preallocated-invalid.ll
@@ -65,13 +65,21 @@ define void @preallocated_one_call() {
ret void
}
-; CHECK: must be a constant
+; CHECK: immarg operand has non-immediate parameter
define void @preallocated_setup_constant() {
%ac = call i32 @blackbox()
%cs = call token @llvm.call.preallocated.setup(i32 %ac)
ret void
}
+; CHECK: llvm.call.preallocated.alloc arg index must be a constant
+define void @preallocated_arg_constant() {
+ %ac = call i32 @blackbox()
+ %cs = call token @llvm.call.preallocated.setup(i32 3)
+ call token @llvm.call.preallocated.arg(token %cs, i32 %ac)
+ ret void
+}
+
; CHECK: must be between 0 and corresponding
define void @preallocated_setup_arg_index_in_bounds() {
%cs = call token @llvm.call.preallocated.setup(i32 2)
More information about the llvm-commits
mailing list