[llvm] [SystemZ] Keep patchable function entries at function start (PR #216762)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 17 09:18:02 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-systemz
Author: Ilya Leoshkevich (iii-i)
<details>
<summary>Changes</summary>
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@<!-- -->linux.ibm.com>
---
Full diff: https://github.com/llvm/llvm-project/pull/216762.diff
2 Files Affected:
- (modified) llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp (+2-1)
- (modified) llvm/test/CodeGen/SystemZ/patchable-function-entry.ll (+19)
``````````diff
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
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/216762
More information about the llvm-commits
mailing list