Skip to content

[Patchpoint] Add immarg attributes to patchpoint arguments #97276

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 4 commits into from
Sep 17, 2024

Conversation

Il-Capitano
Copy link
Contributor

This fixes an issue where simplifycfg would merge two patchpoints, resulting in a dynamic ID being used, which triggers an assert during code generation.

@llvmbot
Copy link
Member

llvmbot commented Jul 1, 2024

@llvm/pr-subscribers-llvm-ir

@llvm/pr-subscribers-llvm-transforms

Author: Csanád Hajdú (Il-Capitano)

Changes

This fixes an issue where simplifycfg would merge two patchpoints, resulting in a dynamic ID being used, which triggers an assert during code generation.


Full diff: https://github.com/llvm/llvm-project/pull/97276.diff

2 Files Affected:

  • (modified) llvm/include/llvm/IR/Intrinsics.td (+6-2)
  • (added) llvm/test/Transforms/SimplifyCFG/patchpoint-invalid-sink.ll (+35)
diff --git a/llvm/include/llvm/IR/Intrinsics.td b/llvm/include/llvm/IR/Intrinsics.td
index c7d383a5d0c0c..332941cadb456 100644
--- a/llvm/include/llvm/IR/Intrinsics.td
+++ b/llvm/include/llvm/IR/Intrinsics.td
@@ -1606,12 +1606,16 @@ def int_experimental_patchpoint_void : Intrinsic<[],
                                                  [llvm_i64_ty, llvm_i32_ty,
                                                   llvm_ptr_ty, llvm_i32_ty,
                                                   llvm_vararg_ty],
-                                                  [Throws]>;
+                                                  [Throws, ImmArg<ArgIndex<0>>,
+                                                   ImmArg<ArgIndex<1>>,
+                                                   ImmArg<ArgIndex<3>>]>;
 def int_experimental_patchpoint : Intrinsic<[llvm_any_ty],
                                             [llvm_i64_ty, llvm_i32_ty,
                                              llvm_ptr_ty, llvm_i32_ty,
                                              llvm_vararg_ty],
-                                            [Throws]>;
+                                            [Throws, ImmArg<ArgIndex<0>>,
+                                             ImmArg<ArgIndex<1>>,
+                                             ImmArg<ArgIndex<3>>]>;
 
 
 //===------------------------ Garbage Collection Intrinsics ---------------===//
diff --git a/llvm/test/Transforms/SimplifyCFG/patchpoint-invalid-sink.ll b/llvm/test/Transforms/SimplifyCFG/patchpoint-invalid-sink.ll
new file mode 100644
index 0000000000000..eeb5710234065
--- /dev/null
+++ b/llvm/test/Transforms/SimplifyCFG/patchpoint-invalid-sink.ll
@@ -0,0 +1,35 @@
+; RUN: opt -passes='simplifycfg<sink-common-insts>' -S %s | FileCheck %s
+
+declare void @personalityFn()
+
+define void @test(i1 %c) personality ptr @personalityFn {
+; CHECK-LABEL: define void @test
+; CHECK-LABEL: entry:
+; CHECK-NEXT:    br i1 %c, label %taken, label %untaken
+; CHECK-LABEL: taken:
+; CHECK-NEXT:    invoke void (i64, i32, ptr, i32, ...) @llvm.experimental.patchpoint.void(i64 1, i32 0, ptr null, i32 0)
+; CHECK-LABEL: untaken:
+; CHECK-NEXT:    invoke void (i64, i32, ptr, i32, ...) @llvm.experimental.patchpoint.void(i64 2, i32 0, ptr null, i32 0)
+; CHECK-LABEL: end:
+; CHECK-NEXT:    ret void
+entry:
+  br i1 %c, label %taken, label %untaken
+
+taken:
+  invoke void (i64, i32, ptr, i32, ...) @llvm.experimental.patchpoint.void(i64 1, i32 0, ptr null, i32 0)
+          to label %end unwind label %unwind
+
+untaken:
+  invoke void (i64, i32, ptr, i32, ...) @llvm.experimental.patchpoint.void(i64 2, i32 0, ptr null, i32 0)
+          to label %end unwind label %unwind
+
+end:
+  ret void
+
+unwind:
+  %0 = landingpad { ptr, i32 }
+          cleanup
+  br label %end
+}
+
+declare void @llvm.experimental.patchpoint.void(i64 immarg, i32 immarg, ptr, i32 immarg, ...)

@Il-Capitano Il-Capitano force-pushed the patchpoint-immarg-attributes branch from cf012a2 to 18a168a Compare July 11, 2024 09:01
@Il-Capitano
Copy link
Contributor Author

@huntergr-arm @fmayer @chapuni Pinging for review.

@Il-Capitano
Copy link
Contributor Author

@huntergr-arm @fmayer @chapuni Ping

@fmayer
Copy link
Contributor

fmayer commented Jul 29, 2024

Sorry for the delay, I was on a break, I will take a look this week.

@fmayer
Copy link
Contributor

fmayer commented Aug 1, 2024

It looks fine to me, but why was I added to this? I don't have experience with patchpoint?

@Il-Capitano
Copy link
Contributor Author

@fmayer You must have been on a blame list for some unrelated change in llvm/include/llvm/IR/Intrinsics.td. Sorry for the confusion, and thanks for taking the time anyways.

@fmayer fmayer removed their request for review August 2, 2024 17:51
@Il-Capitano
Copy link
Contributor Author

@sanjoy @preames @arsenm Can I ask for review of this PR, or can you add appropriate reviewers? There hasn't been much development on this part of LLVM in the past years, so it's hard to find reviewers, and I think this is a fairly trivial bugfix. Thanks!

Copy link
Contributor

@arsenm arsenm left a comment

Choose a reason for hiding this comment

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

Could use coverage in test/Verifier/intrinsic-immarg.ll

This fixes an issue where simplifycfg would merge two patchpoints,
resulting in a dynamic ID being used, which triggers an assert during
code generation.
@Il-Capitano Il-Capitano force-pushed the patchpoint-immarg-attributes branch from 18a168a to 1441856 Compare September 4, 2024 07:48
@Il-Capitano
Copy link
Contributor Author

Thanks for the review!

Could use coverage in test/Verifier/intrinsic-immarg.ll

I added a test case in the latest change.

@Il-Capitano
Copy link
Contributor Author

Can I ask for this to be merged?

@arsenm arsenm merged commit bc8a5d1 into llvm:main Sep 17, 2024
4 of 6 checks passed
@Il-Capitano Il-Capitano deleted the patchpoint-immarg-attributes branch September 17, 2024 17:57
tmsri pushed a commit to tmsri/llvm-project that referenced this pull request Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants