Skip to content

Commit f222259

Browse files
author
Sjoerd Meijer
committed
[ARM] Thumb2: ConstantMaterializationCost
Constants can also be materialised using the negated value and a MVN, and this case seem to have been missed for Thumb2. To check the constant materialisation costs, we now call getT2SOImmVal twice, once for the original constant and then also for its negated value, and this function checks if the constant can both be splatted or rotated. This was revealed by a test that optimises for minsize: instead of a LDR literal pool load and having a literal pool entry, just a MVN with an immediate is smaller (and also faster). Differential Revision: https://reviews.llvm.org/D57327 llvm-svn: 352737
1 parent f7cc34c commit f222259

File tree

2 files changed

+69
-69
lines changed

2 files changed

+69
-69
lines changed

llvm/lib/Target/ARM/ARMISelDAGToDAG.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,10 @@ unsigned ARMDAGToDAGISel::ConstantMaterializationCost(unsigned Val) const {
452452
if (Subtarget->isThumb()) {
453453
if (Val <= 255) return 1; // MOV
454454
if (Subtarget->hasV6T2Ops() &&
455-
(Val <= 0xffff || ARM_AM::getT2SOImmValSplatVal(Val) != -1))
456-
return 1; // MOVW
455+
(Val <= 0xffff || // MOV
456+
ARM_AM::getT2SOImmVal(Val) != -1 || // MOVW
457+
ARM_AM::getT2SOImmVal(~Val) != -1)) // MVN
458+
return 1;
457459
if (Val <= 510) return 2; // MOV + ADDi8
458460
if (~Val <= 255) return 2; // MOV + MVN
459461
if (ARM_AM::isThumbImmShiftedVal(Val)) return 2; // MOV + LSL
Lines changed: 65 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,97 @@
1-
; RUN: llc -mcpu=cortex-a8 -relocation-model=static %s -o - | FileCheck -check-prefix=NO-OPTION %s
2-
; RUN: llc -mcpu=cortex-a8 -relocation-model=static %s -o - -mattr=-no-movt | FileCheck -check-prefix=USE-MOVT %s
3-
; RUN: llc -mcpu=cortex-a8 -relocation-model=static %s -o - -mattr=+no-movt | FileCheck -check-prefix=NO-USE-MOVT %s
4-
; RUN: llc -mcpu=cortex-a8 -relocation-model=static %s -o - -O0 | FileCheck -check-prefix=NO-OPTION-O0 %s
5-
; RUN: llc -mcpu=cortex-a8 -relocation-model=static %s -o - -O0 -mattr=-no-movt | FileCheck -check-prefix=USE-MOVT-O0 %s
6-
; RUN: llc -mcpu=cortex-a8 -relocation-model=static %s -o - -O0 -mattr=+no-movt | FileCheck -check-prefix=NO-USE-MOVT-O0 %s
1+
; RUN: llc -mcpu=cortex-a8 -relocation-model=static %s -o - | \
2+
; RUN: FileCheck -check-prefixes=CHECK,NO-OPTION,NO-OPTION-COMMON %s
3+
; RUN: llc -mcpu=cortex-a8 -relocation-model=static %s -o - -mattr=-no-movt | \
4+
; RUN: FileCheck -check-prefixes=CHECK,USE-MOVT,USE-MOVT-COMMON %s
5+
; RUN: llc -mcpu=cortex-a8 -relocation-model=static %s -o - -mattr=+no-movt | \
6+
; RUN: FileCheck -check-prefixes=CHECK,NO-USE-MOVT,NO-USE-MOVT-COMMON %s
7+
; RUN: llc -mcpu=cortex-a8 -relocation-model=static %s -o - -O0 | \
8+
; RUN: FileCheck -check-prefixes=CHECK,NO-OPTION-O0,NO-OPTION-COMMON %s
9+
; RUN: llc -mcpu=cortex-a8 -relocation-model=static %s -o - -O0 -mattr=-no-movt | \
10+
; RUN: FileCheck -check-prefixes=CHECK,USE-MOVT-O0,USE-MOVT-COMMON %s
11+
; RUN: llc -mcpu=cortex-a8 -relocation-model=static %s -o - -O0 -mattr=+no-movt | \
12+
; RUN: FileCheck -check-prefixes=CHECK,NO-USE-MOVT-O0,NO-USE-MOVT-COMMON %s
713

814
target triple = "thumb-apple-darwin"
915

10-
; NO-OPTION-LABEL: {{_?}}foo0
11-
; NO-OPTION: ldr [[R0:r[0-9]+]], [[L0:.*]]
12-
; NO-OPTION: [[L0]]:
13-
; NO-OPTION: .long 2296237089
16+
; NO-OPTION-COMMON-LABEL: {{_?}}foo0
17+
; NO-OPTION-COMMON: ldr [[R0:r[0-9]+]], [[L0:.*]]
18+
; NO-OPTION-COMMON: [[L0]]:
19+
; NO-OPTION-COMMON: .long 2296237089
1420

15-
; NO-OPTION-O0-LABEL: {{_?}}foo0
16-
; NO-OPTION-O0: ldr [[R0:r[0-9]+]], [[L0:.*]]
17-
; NO-OPTION-O0: [[L0]]:
18-
; NO-OPTION-O0: .long 2296237089
21+
; USE-MOVT-COMMON-LABEL: {{_?}}foo0
22+
; USE-MOVT-COMMON: movw [[R0:r[0-9]+]], #52257
23+
; USE-MOVT-COMMON: movt [[R0]], #35037
1924

20-
; USE-MOVT-LABEL: {{_?}}foo0
21-
; USE-MOVT: movw [[R0:r[0-9]+]], #52257
22-
; USE-MOVT: movt [[R0]], #35037
23-
24-
; USE-MOVT-O0-LABEL: {{_?}}foo0
25-
; USE-MOVT-O0: movw [[R0:r[0-9]+]], #52257
26-
; USE-MOVT-O0: movt [[R0]], #35037
27-
28-
; NO-USE-MOVT-LABEL: {{_?}}foo0
29-
; NO-USE-MOVT: ldr [[R0:r[0-9]+]], [[L0:.*]]
30-
; NO-USE-MOVT: [[L0]]:
31-
; NO-USE-MOVT: .long 2296237089
32-
33-
; NO-USE-MOVT-O0-LABEL: {{_?}}foo0
34-
; NO-USE-MOVT-O0: ldr [[R0:r[0-9]+]], [[L0:.*]]
35-
; NO-USE-MOVT-O0: [[L0]]:
36-
; NO-USE-MOVT-O0: .long 2296237089
25+
; NO-USE-MOVT-COMMON-LABEL: {{_?}}foo0
26+
; NO-USE-MOVT-COMMON: ldr [[R0:r[0-9]+]], [[L0:.*]]
27+
; NO-USE-MOVT-COMMON: [[L0]]:
28+
; NO-USE-MOVT-COMMON: .long 2296237089
3729

3830
define i32 @foo0(i32 %a) #0 {
3931
%1 = xor i32 -1998730207, %a
4032
ret i32 %1
4133
}
4234

43-
; NO-OPTION-LABEL: {{_?}}foo1
44-
; NO-OPTION: movw [[R0:r[0-9]+]], #52257
45-
; NO-OPTION: movt [[R0]], #35037
46-
47-
; NO-OPTION-O0-LABEL: {{_?}}foo1
48-
; NO-OPTION-O0: movw [[R0:r[0-9]+]], #52257
49-
; NO-OPTION-O0: movt [[R0]], #35037
35+
; NO-OPTION-COMMON-LABEL: {{_?}}foo1
36+
; NO-OPTION-COMMON: movw [[R0:r[0-9]+]], #52257
37+
; NO-OPTION-COMMON: movt [[R0]], #35037
5038

51-
; USE-MOVT-LABEL: {{_?}}foo1
52-
; USE-MOVT: movw [[R0:r[0-9]+]], #52257
53-
; USE-MOVT: movt [[R0]], #35037
39+
; USE-MOVT-COMMON-LABEL: {{_?}}foo1
40+
; USE-MOVT-COMMON: movw [[R0:r[0-9]+]], #52257
41+
; USE-MOVT-COMMON: movt [[R0]], #35037
5442

55-
; USE-MOVT-O0-LABEL: {{_?}}foo1
56-
; USE-MOVT-O0: movw [[R0:r[0-9]+]], #52257
57-
; USE-MOVT-O0: movt [[R0]], #35037
58-
59-
; NO-USE-MOVT-LABEL: {{_?}}foo1
60-
; NO-USE-MOVT: ldr [[R0:r[0-9]+]], [[L0:.*]]
61-
; NO-USE-MOVT: [[L0]]:
62-
; NO-USE-MOVT: .long 2296237089
63-
64-
; NO-USE-MOVT-O0-LABEL: {{_?}}foo1
65-
; NO-USE-MOVT-O0: ldr [[R0:r[0-9]+]], [[L0:.*]]
66-
; NO-USE-MOVT-O0: [[L0]]:
67-
; NO-USE-MOVT-O0: .long 2296237089
43+
; NO-USE-MOVT-COMMON-LABEL: {{_?}}foo1
44+
; NO-USE-MOVT-COMMON: ldr [[R0:r[0-9]+]], [[L0:.*]]
45+
; NO-USE-MOVT-COMMON: [[L0]]:
46+
; NO-USE-MOVT-COMMON: .long 2296237089
6847

6948
define i32 @foo1(i32 %a) {
7049
%1 = xor i32 -1998730207, %a
7150
ret i32 %1
7251
}
7352

74-
; NO-OPTION-LABEL: {{_?}}foo2
53+
; NO-OPTION-COMMON-LABEL: {{_?}}foo2
7554
; NO-OPTION: mov.w [[R0:r[0-9]+]], #-536813568
76-
77-
; USE-MOVT-LABEL: {{_?}}foo2
78-
; USE-MOVT: mov.w [[R0:r[0-9]+]], #-536813568
79-
80-
; NO-USE-MOVT-LABEL: {{_?}}foo2
81-
; NO-USE-MOVT: mov.w [[R0:r[0-9]+]], #-536813568
82-
83-
; NO-OPTION-O0-LABEL: {{_?}}foo2
8455
; NO-OPTION-O0: movw [[R0:r[0-9]+]], #57344
8556
; NO-OPTION-O0: movt [[R0]], #57344
8657

87-
; USE-MOVT-O0-LABEL: {{_?}}foo2
88-
; USE-MOVT-O0: movw [[R0:r[0-9]+]], #57344
89-
; USE-MOVTT-O0: movt [[R0]], #57344
58+
; USE-MOVT-COMMON-LABEL: {{_?}}foo2
59+
; USE-MOVT: mov.w [[R0:r[0-9]+]], #-536813568
60+
; USE-MOVT-O0: movw [[R0:r[0-9]+]], #57344
61+
; USE-MOVT-O0: movt [[R0]], #57344
9062

91-
; NO-USE-MOVT-O0-LABEL: {{_?}}foo2
63+
; NO-USE-MOVT-COMMON-LABEL: {{_?}}foo2
64+
; NO-USE-MOVT: mov.w [[R0:r[0-9]+]], #-536813568
9265
; NO-USE-MOVT-O0: ldr [[R0:r[0-9]+]], [[L0:.*]]
9366
; NO-USE-MOVT-O0: [[L0]]:
9467
; NO-USE-MOVT-O0: .long 3758153728 @ 0xe000e000
68+
9569
define i32 @foo2() {
9670
%1 = load i32, i32* inttoptr (i32 -536813568 to i32*) ; load from 0xe000e000
9771
ret i32 %1
9872
}
9973
attributes #0 = { "target-features"="+no-movt" }
74+
75+
define hidden i32 @no_litpool() minsize optsize {
76+
; CHECK-LABEL: no_litpool:
77+
; CHECK: mov.w r{{.}}, #65536
78+
; CHECK: mov.w r{{.}}, #-134217728
79+
; CHECK: mvn r{{.}}, #-134217728
80+
entry:
81+
%call0 = tail call i32 @eat_const(i32 65536)
82+
%call1 = tail call i32 @eat_const(i32 -134217728)
83+
%call2 = tail call i32 @eat_const(i32 134217727)
84+
ret i32 %call2
85+
}
86+
87+
define hidden i32 @litpool() minsize optsize {
88+
; CHECK-LABEL: litpool:
89+
; CHECK: ldr r0, {{.*}}LCPI{{.*}}
90+
; CHECK-NEXT: b.w {{.*}}eat_const
91+
entry:
92+
%call1 = tail call i32 @eat_const(i32 8388601)
93+
ret i32 %call1
94+
}
95+
96+
declare dso_local i32 @eat_const(i32)
97+

0 commit comments

Comments
 (0)