Skip to content

Commit 3209077

Browse files
Yuanfang Chentstellar
authored andcommitted
[X86] make sure POP has implicit def/use of stack pointer when materializing 8-bit immediates for minsize
Summary: Otherwise PostRA list scheduler may reorder instruction, such as schedule this ''' pushq $0x8 pop %rbx lea 0x2a0(%rsp),%r15 ''' to ''' pushq $0x8 lea 0x2a0(%rsp),%r15 pop %rbx ''' by mistake. The patch is to prevent this to happen by making sure POP has implicit use of SP. Reviewers: craig.topper Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77031 (cherry picked from commit ece79f4)
1 parent dc94773 commit 3209077

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

llvm/lib/Target/X86/X86InstrInfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3956,6 +3956,8 @@ static bool ExpandMOVImmSExti8(MachineInstrBuilder &MIB,
39563956
BuildMI(MBB, I, DL, TII.get(X86::PUSH32i8)).addImm(Imm);
39573957
MIB->setDesc(TII.get(X86::POP32r));
39583958
}
3959+
MIB->RemoveOperand(1);
3960+
MIB->addImplicitDefUseOperands(*MBB.getParent());
39593961

39603962
// Build CFI if necessary.
39613963
MachineFunction &MF = *MBB.getParent();

llvm/test/CodeGen/X86/materialize.ll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+cmov %s -o - | FileCheck %s --check-prefix=CHECK64
33
; RUN: llc -mtriple=x86_64-pc-win32 -mattr=+cmov %s -o - | FileCheck %s --check-prefix=CHECKWIN64
44

5+
; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=+cmov %s -o /dev/null \
6+
; RUN: -print-after postrapseudos -filter-print-funcs pr26023 2>&1 \
7+
; RUN: | FileCheck %s --check-prefix=OPERAND32
8+
; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+cmov %s -o /dev/null \
9+
; RUN: -print-after postrapseudos -filter-print-funcs one64_minsize 2>&1 \
10+
; RUN: | FileCheck %s --check-prefix=OPERAND64
11+
512
define i32 @one32_nooptsize() {
613
entry:
714
ret i32 1
@@ -92,6 +99,12 @@ entry:
9299
; CHECK32: pushl $5
93100
; CHECK32: popl %ecx
94101
; CHECK32: retl
102+
103+
; Check push/pop have implicit def/use of $esp
104+
; OPERAND32: PUSH32i8 5, implicit-def $esp, implicit $esp
105+
; OPERAND32-NEXT: CFI_INSTRUCTION adjust_cfa_offset 4
106+
; OPERAND32-NEXT: renamable $ecx = POP32r implicit-def $esp, implicit $esp
107+
; OPERAND32-NEXT: CFI_INSTRUCTION adjust_cfa_offset -4
95108
}
96109

97110

@@ -110,6 +123,13 @@ entry:
110123
; CHECKWIN64-LABEL: one64_minsize:
111124
; CHECKWIN64: movl $1, %eax
112125
; CHECKWIN64-NEXT: retq
126+
127+
; Check push/pop have implicit def/use of $rsp
128+
; OPERAND64: PUSH64i8 1, implicit-def $rsp, implicit $rsp
129+
; OPERAND64-NEXT: CFI_INSTRUCTION adjust_cfa_offset 8
130+
; OPERAND64-NEXT: $rax = POP64r implicit-def $rsp, implicit $rsp
131+
; OPERAND64-NEXT: CFI_INSTRUCTION adjust_cfa_offset -8
132+
; OPERAND64-NEXT: RET 0, $rax
113133
}
114134

115135
define i32 @minus_one32() optsize {

0 commit comments

Comments
 (0)