[llvm] 3161d70 - [SystemZ] Keep patchable function entries at function start (#216762)

via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 18 05:04:28 PDT 2026


Author: Ilya Leoshkevich
Date: 2026-08-18T14:04:22+02:00
New Revision: 3161d7045c1aaadb0cf535c76d6b8b0c75ea3d12

URL: https://github.com/llvm/llvm-project/commit/3161d7045c1aaadb0cf535c76d6b8b0c75ea3d12
DIFF: https://github.com/llvm/llvm-project/commit/3161d7045c1aaadb0cf535c76d6b8b0c75ea3d12.diff

LOG: [SystemZ] Keep patchable function entries at function start (#216762)

Currently SystemZ's PostRA Scheduler is allowed to move
PATCHABLE_FUNCTION_ENTER around, defeating its purpose:

    bb.0 (%ir-block.0):
      PATCHABLE_FUNCTION_ENTER
      $r2d = LGHI 1

    [...]

# *** IR Dump After PostRA Machine Instruction Scheduler (postmisched)
***:

    [...]

    bb.0 (%ir-block.0):
      $r2d = LGHI 1
      PATCHABLE_FUNCTION_ENTER

Fix this by designating it a scheduling boundary, making
PostRAScheduler::run() create regions around it.

SystemZ needs this, unlike, e.g., X86, because its PatchableFunction
pass runs before PostRAScheduler.

Co-developed-by: Vasily Gorbik <gor at linux.ibm.com>

Added: 
    

Modified: 
    llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp
    llvm/test/CodeGen/SystemZ/patchable-function-entry.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp b/llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp
index 58aec25c63416..bfffa39117443 100644
--- a/llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp
@@ -2449,7 +2449,8 @@ bool SystemZInstrInfo::isSchedulingBoundary(const MachineInstr &MI,
                                             const MachineFunction &MF) const {
   if (TargetInstrInfo::isSchedulingBoundary(MI, MBB, MF))
     return true;
-  return MI.getOpcode() == SystemZ::FENCE;
+  return MI.getOpcode() == SystemZ::FENCE ||
+         MI.getOpcode() == TargetOpcode::PATCHABLE_FUNCTION_ENTER;
 }
 
 MCInst SystemZInstrInfo::getNop() const {

diff  --git a/llvm/test/CodeGen/SystemZ/patchable-function-entry.ll b/llvm/test/CodeGen/SystemZ/patchable-function-entry.ll
index 037e4152af6c5..34e57720ef2dd 100644
--- a/llvm/test/CodeGen/SystemZ/patchable-function-entry.ll
+++ b/llvm/test/CodeGen/SystemZ/patchable-function-entry.ll
@@ -2,6 +2,7 @@
 ; RUN: llc -mtriple=s390x-ibm-linux -function-sections %s -o - | FileCheck %s
 ; RUN: llc -mtriple=s390x-ibm-linux -no-integrated-as -binutils-version=2.35 %s -o - | FileCheck --check-prefix=NOLINK %s
 ; RUN: llc -mtriple=s390x-ibm-linux -no-integrated-as -binutils-version=2.36 %s -o - | FileCheck %s
+; RUN: llc -mtriple=s390x-ibm-linux -mcpu=zEC12 %s -o - | FileCheck %s --check-prefix=ZEC12
 
 ;; GNU ld < 2.36 did not support mixed SHF_LINK_ORDER and non-SHF_LINK_ORDER sections.
 ; NOLINK-NOT: "awo"
@@ -99,3 +100,21 @@ define void @prefix() "patchable-function-entry"="0" "patchable-function-prefix"
 ; CHECK-NEXT: .quad   .Ltmp1
   ret void
 }
+
+;; Make sure patchable function entry is not moved around.
+declare void @f4_1(i64)
+
+define void @f4_2() "patchable-function-entry"="3" {
+; ZEC12-LABEL: f4_2:
+; ZEC12-NEXT:  [[ENTRY:.Lfunc_begin[0-9]+]]:
+; ZEC12:       # %bb.0:
+; ZEC12-NEXT:  nopr
+; ZEC12-NEXT:  nopr
+; ZEC12-NEXT:  nopr
+; ZEC12-NEXT:  lghi
+; ZEC12:       .section __patchable_function_entries,"awo", at progbits,f4_2
+; ZEC12-NEXT:  .p2align 3, 0x0
+; ZEC12-NEXT:  .quad [[ENTRY]]
+  tail call void (i64) @f4_1(i64 1)
+  ret void
+}


        


More information about the llvm-commits mailing list