[PATCH] D77031: [X86] make sure POP has implicit def/use of stack pointer when materializing 8-bit immediates for minsize
Yuanfang Chen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 29 21:24:32 PDT 2020
ychen created this revision.
ychen added a reviewer: craig.topper.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D77031
Files:
llvm/lib/Target/X86/X86InstrInfo.cpp
llvm/test/CodeGen/X86/materialize.ll
Index: llvm/test/CodeGen/X86/materialize.ll
===================================================================
--- llvm/test/CodeGen/X86/materialize.ll
+++ llvm/test/CodeGen/X86/materialize.ll
@@ -2,6 +2,13 @@
; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+cmov %s -o - | FileCheck %s --check-prefix=CHECK64
; RUN: llc -mtriple=x86_64-pc-win32 -mattr=+cmov %s -o - | FileCheck %s --check-prefix=CHECKWIN64
+; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=+cmov %s -o /dev/null \
+; RUN: -print-after postrapseudos -filter-print-funcs pr26023 2>&1 \
+; RUN: | FileCheck %s --check-prefix=OPERAND32
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+cmov %s -o /dev/null \
+; RUN: -print-after postrapseudos -filter-print-funcs one64_minsize 2>&1 \
+; RUN: | FileCheck %s --check-prefix=OPERAND64
+
define i32 @one32_nooptsize() {
entry:
ret i32 1
@@ -92,6 +99,12 @@
; CHECK32: pushl $5
; CHECK32: popl %ecx
; CHECK32: retl
+
+; Check push/pop have implicit def/use of $esp
+; OPERAND32: PUSH32i8 5, implicit-def $esp, implicit $esp
+; OPERAND32-NEXT: CFI_INSTRUCTION adjust_cfa_offset 4
+; OPERAND32-NEXT: renamable $ecx = POP32r implicit-def $esp, implicit $esp
+; OPERAND32-NEXT: CFI_INSTRUCTION adjust_cfa_offset -4
}
@@ -110,6 +123,13 @@
; CHECKWIN64-LABEL: one64_minsize:
; CHECKWIN64: movl $1, %eax
; CHECKWIN64-NEXT: retq
+
+; Check push/pop have implicit def/use of $rsp
+; OPERAND64: PUSH64i8 1, implicit-def $rsp, implicit $rsp
+; OPERAND64-NEXT: CFI_INSTRUCTION adjust_cfa_offset 8
+; OPERAND64-NEXT: $rax = POP64r implicit-def $rsp, implicit $rsp
+; OPERAND64-NEXT: CFI_INSTRUCTION adjust_cfa_offset -8
+; OPERAND64-NEXT: RET 0, $rax
}
define i32 @minus_one32() optsize {
Index: llvm/lib/Target/X86/X86InstrInfo.cpp
===================================================================
--- llvm/lib/Target/X86/X86InstrInfo.cpp
+++ llvm/lib/Target/X86/X86InstrInfo.cpp
@@ -4443,6 +4443,8 @@
BuildMI(MBB, I, DL, TII.get(X86::PUSH32i8)).addImm(Imm);
MIB->setDesc(TII.get(X86::POP32r));
}
+ MIB->RemoveOperand(1);
+ MIB->addImplicitDefUseOperands(*MBB.getParent());
// Build CFI if necessary.
MachineFunction &MF = *MBB.getParent();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77031.253486.patch
Type: text/x-patch
Size: 2246 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200330/cacd0283/attachment-0001.bin>
More information about the llvm-commits
mailing list