1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

[X86] Teach -Os immediate sharing code to not count constant uses that will become INC/DEC.

INC/DEC don't use an immediate so we don't need to count it. We
also shouldn't use the custom isel for it.

Fixes PR42998.

llvm-svn: 369863
This commit is contained in:
Craig Topper 2019-08-25 05:22:40 +00:00
parent e06949b64d
commit 9beeb0c2b0
2 changed files with 21 additions and 22 deletions

View File

@ -362,6 +362,11 @@ namespace {
if (User->getNumOperands() != 2)
continue;
// If this can match to INC/DEC, don't count it as a use.
if (User->getOpcode() == ISD::ADD &&
(isOneConstant(SDValue(N, 0)) || isAllOnesConstant(SDValue(N, 0))))
continue;
// Immediates that are used for offsets as part of stack
// manipulation should be left alone. These are typically
// used to indicate SP offsets for argument passing and
@ -4369,6 +4374,10 @@ void X86DAGToDAGISel::Select(SDNode *Node) {
if (!isInt<8>(Val) && !isInt<32>(Val))
break;
// If this can match to INC/DEC, let it go.
if (Opcode == ISD::ADD && (Val == 1 || Val == -1))
break;
// Check if we should avoid folding this immediate.
if (!shouldAvoidImmediateInstFormsForSize(N1.getNode()))
break;

View File

@ -5,12 +5,11 @@
define i64 @imm1_Oz(i32 %x, i32 %y) minsize nounwind {
; CHECK-LABEL: imm1_Oz:
; CHECK: # %bb.0:
; CHECK-NEXT: # kill: def $esi killed $esi def $rsi
; CHECK-NEXT: # kill: def $edi killed $edi def $rdi
; CHECK-NEXT: pushq $1
; CHECK-NEXT: popq %rax
; CHECK-NEXT: leal (%rdi,%rax), %ecx
; CHECK-NEXT: addl %esi, %eax
; CHECK-NEXT: addq %rcx, %rax
; CHECK-NEXT: leal 1(%rdi), %eax
; CHECK-NEXT: incl %esi
; CHECK-NEXT: addq %rsi, %rax
; CHECK-NEXT: retq
%x1 = add i32 %x, 1
%y1 = add i32 %y, 1
@ -21,23 +20,14 @@ define i64 @imm1_Oz(i32 %x, i32 %y) minsize nounwind {
}
define i64 @imm1_Os(i32 %x, i32 %y) optsize nounwind {
; FAST-INCDEC-LABEL: imm1_Os:
; FAST-INCDEC: # %bb.0:
; FAST-INCDEC-NEXT: # kill: def $edi killed $edi def $rdi
; FAST-INCDEC-NEXT: movl $1, %eax
; FAST-INCDEC-NEXT: leal (%rdi,%rax), %ecx
; FAST-INCDEC-NEXT: addl %esi, %eax
; FAST-INCDEC-NEXT: addq %rcx, %rax
; FAST-INCDEC-NEXT: retq
;
; SLOW-INCDEC-LABEL: imm1_Os:
; SLOW-INCDEC: # %bb.0:
; SLOW-INCDEC-NEXT: movl $1, %eax
; SLOW-INCDEC-NEXT: # kill: def $edi killed $edi def $rdi
; SLOW-INCDEC-NEXT: leal (%rdi,%rax), %ecx
; SLOW-INCDEC-NEXT: addl %esi, %eax
; SLOW-INCDEC-NEXT: addq %rcx, %rax
; SLOW-INCDEC-NEXT: retq
; CHECK-LABEL: imm1_Os:
; CHECK: # %bb.0:
; CHECK-NEXT: # kill: def $esi killed $esi def $rsi
; CHECK-NEXT: # kill: def $edi killed $edi def $rdi
; CHECK-NEXT: leal 1(%rdi), %eax
; CHECK-NEXT: incl %esi
; CHECK-NEXT: addq %rsi, %rax
; CHECK-NEXT: retq
%x1 = add i32 %x, 1
%y1 = add i32 %y, 1
%x1z = zext i32 %x1 to i64