[llvm] b32280b - X86: relax EFLAGS liveness check when generating stack probes.

Tim Northover via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 30 03:44:44 PST 2022


Author: Tim Northover
Date: 2022-11-30T11:44:39Z
New Revision: b32280baf9ef46cc0c9f1c700af4fd5c4e1e9acb

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

LOG: X86: relax EFLAGS liveness check when generating stack probes.

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.

Fixes: https://github.com/llvm/llvm-project/issues/59121

Added: 
    

Modified: 
    llvm/lib/Target/X86/X86FrameLowering.cpp
    llvm/test/CodeGen/X86/probe-stack-eflags.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/X86/X86FrameLowering.cpp b/llvm/lib/Target/X86/X86FrameLowering.cpp
index b6fa3d5d4e543..2f1f21f8231df 100644
--- a/llvm/lib/Target/X86/X86FrameLowering.cpp
+++ b/llvm/lib/Target/X86/X86FrameLowering.cpp
@@ -733,7 +733,8 @@ void X86FrameLowering::emitStackProbeInlineGenericLoop(
     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 @@ void X86FrameLowering::emitStackProbeInlineWindowsCoreCLR64(
   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 @@ void X86FrameLowering::emitStackProbeCall(
     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;

diff  --git a/llvm/test/CodeGen/X86/probe-stack-eflags.ll b/llvm/test/CodeGen/X86/probe-stack-eflags.ll
index 28432ef1e3b9a..cc1839bba7e89 100644
--- a/llvm/test/CodeGen/X86/probe-stack-eflags.ll
+++ b/llvm/test/CodeGen/X86/probe-stack-eflags.ll
@@ -75,4 +75,41 @@ exit2: ; preds = %bb70.i, %bb13.i
   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" }


        


More information about the llvm-commits mailing list