-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[IR] Use immarg for preallocated intrinsics (NFC) #155835
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
Conversation
@llvm/pr-subscribers-llvm-ir Author: Nikita Popov (nikic) ChangesMark the attributes as immarg to indicate that they require a constant integer. This was previously enforced with a manual verifier check. Full diff: https://github.com/llvm/llvm-project/pull/155835.diff 3 Files Affected:
diff --git a/llvm/include/llvm/IR/Intrinsics.td b/llvm/include/llvm/IR/Intrinsics.td
index e0ee12391b31d..efecb476c49ee 100644
--- a/llvm/include/llvm/IR/Intrinsics.td
+++ b/llvm/include/llvm/IR/Intrinsics.td
@@ -977,8 +977,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 9fda08645e118..0e1c52a27cfdf 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -5810,9 +5810,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);
@@ -5820,9 +5818,7 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
"Uses of llvm.call.preallocated.setup must be calls");
Intrinsic::ID IID = UseCall->getIntrinsicID();
if (IID == Intrinsic::call_preallocated_arg) {
- auto *AllocArgIndex = dyn_cast<ConstantInt>(UseCall->getArgOperand(1));
- Check(AllocArgIndex != nullptr,
- "llvm.call.preallocated.alloc arg index must be a constant");
+ auto *AllocArgIndex = cast<ConstantInt>(UseCall->getArgOperand(1));
auto AllocArgIndexInt = AllocArgIndex->getValue();
Check(AllocArgIndexInt.sge(0) &&
AllocArgIndexInt.slt(NumArgs->getValue()),
diff --git a/llvm/test/Verifier/preallocated-invalid.ll b/llvm/test/Verifier/preallocated-invalid.ll
index 38ed1067c497d..921fa69dcb23b 100644
--- a/llvm/test/Verifier/preallocated-invalid.ll
+++ b/llvm/test/Verifier/preallocated-invalid.ll
@@ -65,7 +65,7 @@ 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)
|
Ping |
@@ -65,7 +65,7 @@ define void @preallocated_one_call() { | |||
ret void | |||
} | |||
|
|||
; CHECK: must be a constant | |||
; CHECK: immarg operand has non-immediate parameter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing test for the call_preallocated_arg case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair, but that's a pre-existing test coverage gap. This stuff relies on shared infrastructure. How much testing of immarg do we need, especially for a feature which was never productionized?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, this did end up catching an issue in this case. Because part of the validation for preallocated.arg is done when visiting the preallocated.setup, we can't actually assume that the argument is constant in the verifier at that point, so it ended up asserting. I've restored that check, which also means that this doesn't actually produce the immarg message now.
@@ -65,7 +65,7 @@ define void @preallocated_one_call() { | |||
ret void | |||
} | |||
|
|||
; CHECK: must be a constant | |||
; CHECK: immarg operand has non-immediate parameter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair, but that's a pre-existing test coverage gap. This stuff relies on shared infrastructure. How much testing of immarg do we need, especially for a feature which was never productionized?
Mark the attributes as immarg to indicate that they require a constant integer. This was previously enforced with a manual verifier check.
0abc628
to
cd339d8
Compare
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/28329 Here is the relevant piece of the build log for the reference
|
Mark the attributes as immarg to indicate that they require a constant integer. This was previously enforced with a manual verifier check.
Mark the attributes as immarg to indicate that they require a constant integer. This was previously enforced with a manual verifier check.