llvm.org GIT mirror llvm / f5d2383
[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 Craig Topper 26 days ago
2 changed file(s) with 21 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
359359 // This may change in the future as we add additional instruction
360360 // types.
361361 if (User->getNumOperands() != 2)
362 continue;
363
364 // If this can match to INC/DEC, don't count it as a use.
365 if (User->getOpcode() == ISD::ADD &&
366 (isOneConstant(SDValue(N, 0)) || isAllOnesConstant(SDValue(N, 0))))
362367 continue;
363368
364369 // Immediates that are used for offsets as part of stack
43684373 if (!isInt<8>(Val) && !isInt<32>(Val))
43694374 break;
43704375
4376 // If this can match to INC/DEC, let it go.
4377 if (Opcode == ISD::ADD && (Val == 1 || Val == -1))
4378 break;
4379
43714380 // Check if we should avoid folding this immediate.
43724381 if (!shouldAvoidImmediateInstFormsForSize(N1.getNode()))
43734382 break;
44 define i64 @imm1_Oz(i32 %x, i32 %y) minsize nounwind {
55 ; CHECK-LABEL: imm1_Oz:
66 ; CHECK: # %bb.0:
7 ; CHECK-NEXT: # kill: def $esi killed $esi def $rsi
78 ; CHECK-NEXT: # kill: def $edi killed $edi def $rdi
8 ; CHECK-NEXT: pushq $1
9 ; CHECK-NEXT: popq %rax
10 ; CHECK-NEXT: leal (%rdi,%rax), %ecx
11 ; CHECK-NEXT: addl %esi, %eax
12 ; CHECK-NEXT: addq %rcx, %rax
9 ; CHECK-NEXT: leal 1(%rdi), %eax
10 ; CHECK-NEXT: incl %esi
11 ; CHECK-NEXT: addq %rsi, %rax
1312 ; CHECK-NEXT: retq
1413 %x1 = add i32 %x, 1
1514 %y1 = add i32 %y, 1
2019 }
2120
2221 define i64 @imm1_Os(i32 %x, i32 %y) optsize nounwind {
23 ; FAST-INCDEC-LABEL: imm1_Os:
24 ; FAST-INCDEC: # %bb.0:
25 ; FAST-INCDEC-NEXT: # kill: def $edi killed $edi def $rdi
26 ; FAST-INCDEC-NEXT: movl $1, %eax
27 ; FAST-INCDEC-NEXT: leal (%rdi,%rax), %ecx
28 ; FAST-INCDEC-NEXT: addl %esi, %eax
29 ; FAST-INCDEC-NEXT: addq %rcx, %rax
30 ; FAST-INCDEC-NEXT: retq
31 ;
32 ; SLOW-INCDEC-LABEL: imm1_Os:
33 ; SLOW-INCDEC: # %bb.0:
34 ; SLOW-INCDEC-NEXT: movl $1, %eax
35 ; SLOW-INCDEC-NEXT: # kill: def $edi killed $edi def $rdi
36 ; SLOW-INCDEC-NEXT: leal (%rdi,%rax), %ecx
37 ; SLOW-INCDEC-NEXT: addl %esi, %eax
38 ; SLOW-INCDEC-NEXT: addq %rcx, %rax
39 ; SLOW-INCDEC-NEXT: retq
22 ; CHECK-LABEL: imm1_Os:
23 ; CHECK: # %bb.0:
24 ; CHECK-NEXT: # kill: def $esi killed $esi def $rsi
25 ; CHECK-NEXT: # kill: def $edi killed $edi def $rdi
26 ; CHECK-NEXT: leal 1(%rdi), %eax
27 ; CHECK-NEXT: incl %esi
28 ; CHECK-NEXT: addq %rsi, %rax
29 ; CHECK-NEXT: retq
4030 %x1 = add i32 %x, 1
4131 %y1 = add i32 %y, 1
4232 %x1z = zext i32 %x1 to i64