Skip to content

Commit c14f3e4

Browse files
committedMar 21, 2019
[X86] Don't avoid folding multiple use sign extended 8-bit immediate into instructions under optsize.
Under optsize we try to avoid folding immediates into instructions under optsize. But if the immediate is 16-bits or 32 bits, but can be encoded as an 8-bit immediate we don't save enough from disabling the folding unless the immediate has enough uses to make up for the size of the move which is either 3 bytes or 5 bytes since there are no sign extended 8-bit moves. We would also save something if the immediate was a live out of the basic block and thus a move was unavoidable, but that would require a more advanced heuristic than just counting uses. Note we only avoid folding multiple use immediates into the patterns that use X86ISD::ADD/SUB/XOR/OR/AND/CMP/ADC/SBB nodes and not the more common ISD::ADD/SUB/XOR/OR/AND nodes. Differential Revision: https://reviews.llvm.org/D59522 llvm-svn: 356688
1 parent 9f0b17a commit c14f3e4

File tree

5 files changed

+10
-25
lines changed

5 files changed

+10
-25
lines changed
 

‎llvm/lib/Target/X86/X86InstrArithmetic.td

+3-3
Original file line numberDiff line numberDiff line change
@@ -605,13 +605,13 @@ def Xi8 : X86TypeInfo<i8, "b", GR8, loadi8, i8mem,
605605
Imm8, i8imm, relocImm8_su, i8imm, invalid_node,
606606
0, OpSizeFixed, 0>;
607607
def Xi16 : X86TypeInfo<i16, "w", GR16, loadi16, i16mem,
608-
Imm16, i16imm, relocImm16_su, i16i8imm, i16immSExt8_su,
608+
Imm16, i16imm, relocImm16_su, i16i8imm, i16immSExt8,
609609
1, OpSize16, 0>;
610610
def Xi32 : X86TypeInfo<i32, "l", GR32, loadi32, i32mem,
611-
Imm32, i32imm, relocImm32_su, i32i8imm, i32immSExt8_su,
611+
Imm32, i32imm, relocImm32_su, i32i8imm, i32immSExt8,
612612
1, OpSize32, 0>;
613613
def Xi64 : X86TypeInfo<i64, "q", GR64, loadi64, i64mem,
614-
Imm32S, i64i32imm, i64relocImmSExt32_su, i64i8imm, i64immSExt8_su,
614+
Imm32S, i64i32imm, i64relocImmSExt32_su, i64i8imm, i64immSExt8,
615615
1, OpSizeFixed, 1>;
616616

617617
/// ITy - This instruction base class takes the type info for the instruction.

‎llvm/lib/Target/X86/X86InstrCompiler.td

+2-2
Original file line numberDiff line numberDiff line change
@@ -1994,8 +1994,8 @@ def : Pat<(X86sub_flag 0, GR32:$src), (NEG32r GR32:$src)>;
19941994
def : Pat<(X86sub_flag 0, GR64:$src), (NEG64r GR64:$src)>;
19951995

19961996
// sub reg, relocImm
1997-
def : Pat<(X86sub_flag GR64:$src1, i64relocImmSExt8_su:$src2),
1998-
(SUB64ri8 GR64:$src1, i64relocImmSExt8_su:$src2)>;
1997+
def : Pat<(X86sub_flag GR64:$src1, i64relocImmSExt8:$src2),
1998+
(SUB64ri8 GR64:$src1, i64relocImmSExt8:$src2)>;
19991999

20002000
// mul reg, reg
20012001
def : Pat<(mul GR16:$src1, GR16:$src2),

‎llvm/lib/Target/X86/X86InstrInfo.td

-13
Original file line numberDiff line numberDiff line change
@@ -1004,19 +1004,6 @@ def relocImm32_su : PatLeaf<(i32 relocImm), [{
10041004
return !shouldAvoidImmediateInstFormsForSize(N);
10051005
}]>;
10061006

1007-
def i16immSExt8_su : PatLeaf<(i16immSExt8), [{
1008-
return !shouldAvoidImmediateInstFormsForSize(N);
1009-
}]>;
1010-
def i32immSExt8_su : PatLeaf<(i32immSExt8), [{
1011-
return !shouldAvoidImmediateInstFormsForSize(N);
1012-
}]>;
1013-
def i64immSExt8_su : PatLeaf<(i64immSExt8), [{
1014-
return !shouldAvoidImmediateInstFormsForSize(N);
1015-
}]>;
1016-
1017-
def i64relocImmSExt8_su : PatLeaf<(i64relocImmSExt8), [{
1018-
return !shouldAvoidImmediateInstFormsForSize(N);
1019-
}]>;
10201007
def i64relocImmSExt32_su : PatLeaf<(i64relocImmSExt32), [{
10211008
return !shouldAvoidImmediateInstFormsForSize(N);
10221009
}]>;

‎llvm/test/CodeGen/X86/immediate_merging.ll

+4-6
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ define i32 @foo() optsize {
1919
; X86-NEXT: movl $1234, %eax # imm = 0x4D2
2020
; X86-NEXT: movl %eax, a
2121
; X86-NEXT: movl %eax, b
22-
; X86-NEXT: movl $12, %eax
23-
; X86-NEXT: movl %eax, c
24-
; X86-NEXT: cmpl %eax, e
22+
; X86-NEXT: movl $12, c
23+
; X86-NEXT: cmpl $12, e
2524
; X86-NEXT: jne .LBB0_2
2625
; X86-NEXT: # %bb.1: # %if.then
2726
; X86-NEXT: movl $1, x
@@ -38,9 +37,8 @@ define i32 @foo() optsize {
3837
; X64-NEXT: movl $1234, %eax # imm = 0x4D2
3938
; X64-NEXT: movl %eax, {{.*}}(%rip)
4039
; X64-NEXT: movl %eax, {{.*}}(%rip)
41-
; X64-NEXT: movl $12, %eax
42-
; X64-NEXT: movl %eax, {{.*}}(%rip)
43-
; X64-NEXT: cmpl %eax, {{.*}}(%rip)
40+
; X64-NEXT: movl $12, {{.*}}(%rip)
41+
; X64-NEXT: cmpl $12, {{.*}}(%rip)
4442
; X64-NEXT: jne .LBB0_2
4543
; X64-NEXT: # %bb.1: # %if.then
4644
; X64-NEXT: movl $1, {{.*}}(%rip)

‎llvm/test/CodeGen/X86/immediate_merging64.ll

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ define i1 @imm_multiple_users(i64 %a, i64* %b) optsize {
1111
; CHECK: # %bb.0:
1212
; CHECK-NEXT: movq $-1, %rax
1313
; CHECK-NEXT: movq %rax, (%rsi)
14-
; CHECK-NEXT: cmpq %rax, %rdi
14+
; CHECK-NEXT: cmpq $-1, %rdi
1515
; CHECK-NEXT: sete %al
1616
; CHECK-NEXT: retq
1717
store i64 -1, i64* %b, align 8

0 commit comments

Comments
 (0)
Please sign in to comment.