Skip to content

[PPC64] Convert assert in patchpoint emission to usage error.#177453

Merged
mandlebug merged 1 commit intollvm:mainfrom
mandlebug:ConvertPatchpointAssertToError
Jan 22, 2026
Merged

[PPC64] Convert assert in patchpoint emission to usage error.#177453
mandlebug merged 1 commit intollvm:mainfrom
mandlebug:ConvertPatchpointAssertToError

Conversation

@mandlebug
Copy link
Copy Markdown
Member

If the patchpoint intrinsic has requested less bytes then it takes to make the call then report a fatal usage error. Also fixed a bug where we forgot to count one of the instructions emitted.

If the patchpoint intrinsic has requested less bytes then it takes
to make the call then report a fatal usage error. Also fixed a bug
where we forgot to count one of the instructions emitted.
@llvmbot
Copy link
Copy Markdown
Member

llvmbot commented Jan 22, 2026

@llvm/pr-subscribers-backend-powerpc

Author: Sean Fertile (mandlebug)

Changes

If the patchpoint intrinsic has requested less bytes then it takes to make the call then report a fatal usage error. Also fixed a bug where we forgot to count one of the instructions emitted.


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

2 Files Affected:

  • (modified) llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp (+10-2)
  • (added) llvm/test/CodeGen/PowerPC/ppc64-patchpoint-size-check.ll (+15)
diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
index 122738caa6827..49c91d551805f 100644
--- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -578,20 +578,24 @@ void PPCAsmPrinter::LowerPATCHPOINT(StackMaps &SM, const MachineInstr &MI) {
                                       .addReg(ScratchReg)
                                       .addImm((CallTarget >> 32) & 0xFFFF));
       ++EncodedBytes;
+
       EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::RLDIC)
                                       .addReg(ScratchReg)
                                       .addReg(ScratchReg)
                                       .addImm(32).addImm(16));
       ++EncodedBytes;
+
       EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::ORIS8)
                                       .addReg(ScratchReg)
                                       .addReg(ScratchReg)
                                       .addImm((CallTarget >> 16) & 0xFFFF));
       ++EncodedBytes;
+
       EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::ORI8)
                                       .addReg(ScratchReg)
                                       .addReg(ScratchReg)
                                       .addImm(CallTarget & 0xFFFF));
+      ++EncodedBytes;
 
       // Save the current TOC pointer before the remote call.
       int TOCSaveOffset = Subtarget->getFrameLowering()->getTOCSaveOffset();
@@ -612,6 +616,7 @@ void PPCAsmPrinter::LowerPATCHPOINT(StackMaps &SM, const MachineInstr &MI) {
                                         .addImm(8)
                                         .addReg(ScratchReg));
         ++EncodedBytes;
+
         EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::LD)
                                         .addReg(ScratchReg)
                                         .addImm(0)
@@ -622,6 +627,7 @@ void PPCAsmPrinter::LowerPATCHPOINT(StackMaps &SM, const MachineInstr &MI) {
       EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::MTCTR8)
                                       .addReg(ScratchReg));
       ++EncodedBytes;
+
       EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::BCTRL8));
       ++EncodedBytes;
 
@@ -647,8 +653,10 @@ void PPCAsmPrinter::LowerPATCHPOINT(StackMaps &SM, const MachineInstr &MI) {
 
   // Emit padding.
   unsigned NumBytes = Opers.getNumPatchBytes();
-  assert(NumBytes >= EncodedBytes &&
-         "Patchpoint can't request size less than the length of a call.");
+  if (NumBytes < EncodedBytes)
+    reportFatalUsageError(
+        "Patchpoint can't request size less than the length of a call.");
+
   assert((NumBytes - EncodedBytes) % 4 == 0 &&
          "Invalid number of NOP bytes requested!");
   for (unsigned i = EncodedBytes; i < NumBytes; i += 4)
diff --git a/llvm/test/CodeGen/PowerPC/ppc64-patchpoint-size-check.ll b/llvm/test/CodeGen/PowerPC/ppc64-patchpoint-size-check.ll
new file mode 100644
index 0000000000000..d38846f200d4c
--- /dev/null
+++ b/llvm/test/CodeGen/PowerPC/ppc64-patchpoint-size-check.ll
@@ -0,0 +1,15 @@
+; RUN: not llc -mtriple=powerpc64-unknown-linux -verify-machineinstrs 2>&1 < %s | FileCheck %s
+
+define void @func(i64 %a, i64 %b) {
+entry:
+  %test = icmp slt i64 %a, %b
+  br i1 %test, label %ret, label %cold
+cold:
+  %thunk = inttoptr i64 244837814094590 to ptr
+  call void (i64, i32, ptr, i32, ...) @llvm.experimental.patchpoint.void(i64 4, i32 36, ptr %thunk, i32 0, i64 %a, i64 %b)
+  unreachable
+ret:
+  ret void
+}
+
+; CHECK: LLVM ERROR: Patchpoint can't request size less than the length of a call.

Copy link
Copy Markdown
Contributor

@lei137 lei137 left a comment

Choose a reason for hiding this comment

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

LGTM

@mandlebug mandlebug merged commit 30fc5c1 into llvm:main Jan 22, 2026
11 of 12 checks passed
c-rhodes pushed a commit to llvmbot/llvm-project that referenced this pull request Jan 27, 2026
…77453)

If the patchpoint intrinsic has requested less bytes then it takes to
make the call then report a fatal usage error. Also fixed a bug where we
forgot to count one of the instructions emitted.

(cherry picked from commit 30fc5c1)
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.

3 participants