[llvm] r369863 - [X86] Teach -Os immediate sharing code to not count constant uses that will become INC/DEC.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 24 22:22:40 PDT 2019
Author: ctopper
Date: Sat Aug 24 22:22:40 2019
New Revision: 369863
URL: http://llvm.org/viewvc/llvm-project?rev=369863&view=rev
Log:
[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.
Modified:
llvm/trunk/lib/Target/X86/X86ISelDAGToDAG.cpp
llvm/trunk/test/CodeGen/X86/pr42998.ll
Modified: llvm/trunk/lib/Target/X86/X86ISelDAGToDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelDAGToDAG.cpp?rev=369863&r1=369862&r2=369863&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelDAGToDAG.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelDAGToDAG.cpp Sat Aug 24 22:22:40 2019
@@ -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 *Nod
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;
Modified: llvm/trunk/test/CodeGen/X86/pr42998.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/pr42998.ll?rev=369863&r1=369862&r2=369863&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/pr42998.ll (original)
+++ llvm/trunk/test/CodeGen/X86/pr42998.ll Sat Aug 24 22:22:40 2019
@@ -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) mins
}
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
More information about the llvm-commits
mailing list