[llvm] [Patchpoint] Add immarg attributes to patchpoint arguments (PR #97276)
Csanád Hajdú via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 11 02:01:50 PDT 2024
https://github.com/Il-Capitano updated https://github.com/llvm/llvm-project/pull/97276
>From 18a168aa8850107f80935362125ac8bfa948d6d8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Csan=C3=A1d=20Hajd=C3=BA?= <csanad.hajdu at arm.com>
Date: Thu, 20 Jun 2024 16:35:48 +0200
Subject: [PATCH] [Patchpoint] Add immarg attributes to patchpoint arguments
This fixes an issue where simplifycfg would merge two patchpoints,
resulting in a dynamic ID being used, which triggers an assert during
code generation.
---
llvm/include/llvm/IR/Intrinsics.td | 8 +++--
.../SimplifyCFG/patchpoint-invalid-sink.ll | 35 +++++++++++++++++++
2 files changed, 41 insertions(+), 2 deletions(-)
create mode 100644 llvm/test/Transforms/SimplifyCFG/patchpoint-invalid-sink.ll
diff --git a/llvm/include/llvm/IR/Intrinsics.td b/llvm/include/llvm/IR/Intrinsics.td
index 65a9b68b5229d..994f4c8d82164 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, ...)
More information about the llvm-commits
mailing list