[PATCH] D138486: X86: relax EFLAGS liveness check when generating stack probes.
Tim Northover via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 22 03:29:38 PST 2022
t.p.northover created this revision.
t.p.northover added a reviewer: RKSimon.
Herald added subscribers: pengfei, hiraditya, mcrosier.
Herald added a project: All.
t.p.northover requested review of this revision.
Herald added a project: LLVM.
The probes are all inserted at the iterator passed into the functions, so that's where any EFLAGS clobbering will happen and where we need it to be dead.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D138486
Files:
llvm/lib/Target/X86/X86FrameLowering.cpp
llvm/test/CodeGen/X86/probe-stack-eflags.ll
Index: llvm/test/CodeGen/X86/probe-stack-eflags.ll
===================================================================
--- llvm/test/CodeGen/X86/probe-stack-eflags.ll
+++ llvm/test/CodeGen/X86/probe-stack-eflags.ll
@@ -75,4 +75,41 @@
ret i32 %.1.i
}
+define void @CSE_eflags_live(i64 %length) "probe-stack"="__chkstk_darwin" {
+; CHECK-LABEL: CSE_eflags_live:
+; 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: testq %rdi, %rdi
+; CHECK-NEXT: je .LBB1_2
+; CHECK-NEXT: # %bb.1: # %if.end6
+; CHECK-NEXT: movq $-1, %rax
+; CHECK-NEXT: cmovnsq %rdi, %rax
+; CHECK-NEXT: addq $15, %rax
+; CHECK-NEXT: andq $-16, %rax
+; CHECK-NEXT: callq __chkstk_darwin
+; CHECK-NEXT: subq %rax, %rsp
+; CHECK-NEXT: .LBB1_2: # %cleanup78
+; CHECK-NEXT: movq %rbp, %rsp
+; CHECK-NEXT: popq %rbp
+; CHECK-NEXT: .cfi_def_cfa %rsp, 8
+; CHECK-NEXT: retq
+entry:
+ %cmp4 = icmp eq i64 %length, 0
+ br i1 %cmp4, label %cleanup78, label %if.end6
+
+if.end6:
+ %0 = tail call i64 @llvm.smax.i64(i64 %length, i64 -1)
+ %vla = alloca i8, i64 %0, align 16
+ br label %cleanup78
+
+cleanup78:
+ ret void
+}
+
+declare i64 @llvm.smax.i64(i64, i64)
+
attributes #0 = { nounwind "probe-stack"="inline-asm" }
Index: llvm/lib/Target/X86/X86FrameLowering.cpp
===================================================================
--- llvm/lib/Target/X86/X86FrameLowering.cpp
+++ llvm/lib/Target/X86/X86FrameLowering.cpp
@@ -733,7 +733,8 @@
uint64_t AlignOffset) const {
assert(Offset && "null offset");
- assert(!MBB.isLiveIn(X86::EFLAGS) &&
+ assert(MBB.computeRegisterLiveness(TRI, X86::EFLAGS, MBBI) !=
+ MachineBasicBlock::LQR_Live &&
"Inline stack probe loop will clobber live EFLAGS.");
const bool NeedsDwarfCFI = needsDwarfCFI(MF);
@@ -873,7 +874,8 @@
const TargetInstrInfo &TII = *STI.getInstrInfo();
const BasicBlock *LLVM_BB = MBB.getBasicBlock();
- assert(!MBB.isLiveIn(X86::EFLAGS) &&
+ assert(MBB.computeRegisterLiveness(TRI, X86::EFLAGS, MBBI) !=
+ MachineBasicBlock::LQR_Live &&
"Inline stack probe loop will clobber live EFLAGS.");
// RAX contains the number of bytes of desired stack adjustment.
@@ -1112,7 +1114,8 @@
report_fatal_error("Emitting stack probe calls on 64-bit with the large "
"code model and indirect thunks not yet implemented.");
- assert(!MBB.isLiveIn(X86::EFLAGS) &&
+ assert(MBB.computeRegisterLiveness(TRI, X86::EFLAGS, MBBI) !=
+ MachineBasicBlock::LQR_Live &&
"Stack probe calls will clobber live EFLAGS.");
unsigned CallOp;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138486.477128.patch
Type: text/x-patch
Size: 2800 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221122/b27bacb9/attachment.bin>
More information about the llvm-commits
mailing list