[llvm] 0b092df - [X86] Don't save/restore fp around longjmp instructions (#102556)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 17 11:51:09 PDT 2024
Author: weiguozhi
Date: 2024-08-17T11:51:05-07:00
New Revision: 0b092dfee3c5d9d7e4bde636330ce39a656ee676
URL: https://github.com/llvm/llvm-project/commit/0b092dfee3c5d9d7e4bde636330ce39a656ee676
DIFF: https://github.com/llvm/llvm-project/commit/0b092dfee3c5d9d7e4bde636330ce39a656ee676.diff
LOG: [X86] Don't save/restore fp around longjmp instructions (#102556)
Longjmp instructions can also modify fp register, it is expected
behavior. We should not save/restore fp around these instructions.
Added:
Modified:
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/clobber_frame_ptr.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index e0face6b6a7904..2fa416f2e331c4 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -36208,6 +36208,7 @@ X86TargetLowering::emitEHSjLjLongJmp(MachineInstr &MI,
MIB.add(MO);
}
MIB.setMemRefs(MMOs);
+ MIB.setMIFlag(MachineInstr::FrameDestroy);
// Reload IP
MIB = BuildMI(*thisMBB, MI, MIMD, TII->get(PtrLoadOpc), Tmp);
@@ -36233,6 +36234,7 @@ X86TargetLowering::emitEHSjLjLongJmp(MachineInstr &MI,
// the last instruction of the expansion.
}
MIB.setMemRefs(MMOs);
+ MIB.setMIFlag(MachineInstr::FrameDestroy);
// Jump
BuildMI(*thisMBB, MI, MIMD, TII->get(IJmpOpc)).addReg(Tmp);
diff --git a/llvm/test/CodeGen/X86/clobber_frame_ptr.ll b/llvm/test/CodeGen/X86/clobber_frame_ptr.ll
index 6209e1a85e9e19..fd8ba7feb9f48f 100644
--- a/llvm/test/CodeGen/X86/clobber_frame_ptr.ll
+++ b/llvm/test/CodeGen/X86/clobber_frame_ptr.ll
@@ -157,3 +157,46 @@ define i64 @test3(i64 %a0, i64 %a1, i64 %a2, i64 %a3, i64 %a4, i64 %a5, i64 %a6,
%x = call cc 11 i64 @hipe2(i64 %a0, i64 %a1, i64 %a2, i64 %a3, i64 %a4, i64 %a5, i64 %a6, i64 %a7)
ret i64 %x
}
+
+ at buf = dso_local global [20 x ptr] zeroinitializer, align 16
+
+; longjmp modifies fp, it is expected behavior, wo should not save/restore fp
+; around it.
+define void @test4() {
+; CHECK-LABEL: test4:
+; CHECK: # %bb.0: # %entry
+; CHECK-NEXT: pushq %rbp
+; CHECK-NEXT: .cfi_def_cfa_offset 16
+; CHECK-NEXT: .cfi_offset %rbp, -16
+; CHECK-NEXT: movq %rsp, %rbp
+; CHECK-NEXT: .cfi_def_cfa_register %rbp
+; CHECK-NEXT: pushq %r15
+; CHECK-NEXT: pushq %r14
+; CHECK-NEXT: pushq %r13
+; CHECK-NEXT: pushq %r12
+; CHECK-NEXT: pushq %rbx
+; CHECK-NEXT: andq $-16, %rsp
+; CHECK-NEXT: subq $16, %rsp
+; CHECK-NEXT: .cfi_offset %rbx, -56
+; CHECK-NEXT: .cfi_offset %r12, -48
+; CHECK-NEXT: .cfi_offset %r13, -40
+; CHECK-NEXT: .cfi_offset %r14, -32
+; CHECK-NEXT: .cfi_offset %r15, -24
+; CHECK-NEXT: pushq %rbp
+; CHECK-NEXT: pushq %rax
+; CHECK-NEXT: .cfi_remember_state
+; CHECK-NEXT: .cfi_escape 0x0f, 0x06, 0x77, 0x08, 0x06, 0x11, 0x10, 0x22 #
+; CHECK-NEXT: xorl %r13d, %r13d
+; CHECK-NEXT: callq external at PLT
+; CHECK-NEXT: addq $8, %rsp
+; CHECK-NEXT: popq %rbp
+; CHECK-NEXT: .cfi_restore_state
+; CHECK-NEXT: movq buf(%rip), %rbp
+; CHECK-NEXT: movq buf+8(%rip), %rax
+; CHECK-NEXT: movq buf+16(%rip), %rsp
+; CHECK-NEXT: jmpq *%rax
+entry:
+ %x = call ghccc i32 @external(i32 0)
+ call void @llvm.eh.sjlj.longjmp(ptr @buf)
+ unreachable
+}
More information about the llvm-commits
mailing list