Skip to content

Commit

Permalink
[X86] Fix cmp order in probing BuildStackAlignAND
Browse files Browse the repository at this point in the history
Due to reversed arguments, the loop start was almost always skipping the
whole loop, since FinalStackProbed is probably less than StackPtr for
large alignments. The intent was to skip the loop if the first sub on
StackPtr made it less than FinalStackProbed already, so flip it.

Reviewed By: serge-sans-paille

Differential Revision: https://reviews.llvm.org/D139756
  • Loading branch information
cuviper committed Dec 13, 2022
1 parent d08e3ae commit 9b8fcd0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions llvm/lib/Target/X86/X86FrameLowering.cpp
Expand Up @@ -1293,11 +1293,11 @@ void X86FrameLowering::BuildStackAlignAND(MachineBasicBlock &MBB,

BuildMI(headMBB, DL,
TII.get(Uses64BitFramePtr ? X86::CMP64rr : X86::CMP32rr))
.addReg(FinalStackProbed)
.addReg(StackPtr)
.addReg(FinalStackProbed)
.setMIFlag(MachineInstr::FrameSetup);

// jump
// jump to the footer if StackPtr < FinalStackProbed
BuildMI(headMBB, DL, TII.get(X86::JCC_1))
.addMBB(footMBB)
.addImm(X86::COND_B)
Expand Down Expand Up @@ -1329,7 +1329,7 @@ void X86FrameLowering::BuildStackAlignAND(MachineBasicBlock &MBB,
.addReg(StackPtr)
.setMIFlag(MachineInstr::FrameSetup);

// jump
// jump back while FinalStackProbed < StackPtr
BuildMI(bodyMBB, DL, TII.get(X86::JCC_1))
.addMBB(bodyMBB)
.addImm(X86::COND_B)
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/X86/stack-clash-large-large-align.ll
Expand Up @@ -44,7 +44,7 @@ define i32 @foo_protect() local_unnamed_addr #0 {
; CHECK-NEXT: je .LBB1_4
; CHECK-NEXT: # %bb.1:
; CHECK-NEXT: subq $4096, %rsp # imm = 0x1000
; CHECK-NEXT: cmpq %rsp, %r11
; CHECK-NEXT: cmpq %r11, %rsp
; CHECK-NEXT: jb .LBB1_3
; CHECK-NEXT: .LBB1_2: # =>This Inner Loop Header: Depth=1
; CHECK-NEXT: movq $0, (%rsp)
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/X86/stack-clash-small-large-align.ll
Expand Up @@ -40,7 +40,7 @@ define i32 @foo_protect() local_unnamed_addr #0 {
; CHECK-NEXT: je .LBB1_4
; CHECK-NEXT: # %bb.1:
; CHECK-NEXT: subq $4096, %rsp # imm = 0x1000
; CHECK-NEXT: cmpq %rsp, %r11
; CHECK-NEXT: cmpq %r11, %rsp
; CHECK-NEXT: jb .LBB1_3
; CHECK-NEXT: .LBB1_2: # =>This Inner Loop Header: Depth=1
; CHECK-NEXT: movq $0, (%rsp)
Expand Down

0 comments on commit 9b8fcd0

Please sign in to comment.