From: Craig Topper Date: Sun, 25 Aug 2019 05:22:40 +0000 (+0000) Subject: [X86] Teach -Os immediate sharing code to not count constant uses that will become... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f5d23835e6388da47d91729f1bba0a67e0c61ed2;p=llvm [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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@369863 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/X86/X86ISelDAGToDAG.cpp b/lib/Target/X86/X86ISelDAGToDAG.cpp index 46886419421..e0a462471a7 100644 --- a/lib/Target/X86/X86ISelDAGToDAG.cpp +++ b/lib/Target/X86/X86ISelDAGToDAG.cpp @@ -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; diff --git a/test/CodeGen/X86/pr42998.ll b/test/CodeGen/X86/pr42998.ll index 6d67417286a..e3d6a560a11 100644 --- a/test/CodeGen/X86/pr42998.ll +++ b/test/CodeGen/X86/pr42998.ll @@ -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