Skip to content

Commit 55c625f

Browse files
committedJan 23, 2014
ARM: use litpools for normal i32 imms when compiling minsize.
With constant-sharing, litpool loads consume 4 + N*2 bytes of code, but movw/movt pairs consume 8*N. This means litpools are better than movw/movt even with just one use. Other materialisation strategies can still be better though, so the logic is a little odd. llvm-svn: 199891
1 parent e1b5bdd commit 55c625f

File tree

4 files changed

+70
-11
lines changed

4 files changed

+70
-11
lines changed
 

‎llvm/lib/Target/ARM/ARMISelDAGToDAG.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -2472,19 +2472,21 @@ SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
24722472
case ISD::Constant: {
24732473
unsigned Val = cast<ConstantSDNode>(N)->getZExtValue();
24742474
bool UseCP = true;
2475-
if (Subtarget->hasThumb2())
2475+
if (Subtarget->useMovt())
24762476
// Thumb2-aware targets have the MOVT instruction, so all immediates can
24772477
// be done with MOV + MOVT, at worst.
2478-
UseCP = 0;
2478+
UseCP = false;
24792479
else {
24802480
if (Subtarget->isThumb()) {
2481-
UseCP = (Val > 255 && // MOV
2482-
~Val > 255 && // MOV + MVN
2483-
!ARM_AM::isThumbImmShiftedVal(Val)); // MOV + LSL
2481+
UseCP = (Val > 255 && // MOV
2482+
~Val > 255 && // MOV + MVN
2483+
!ARM_AM::isThumbImmShiftedVal(Val) && // MOV + LSL
2484+
!(Subtarget->hasV6T2Ops() && Val <= 0xffff)); // MOVW
24842485
} else
2485-
UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2486-
ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2487-
!ARM_AM::isSOImmTwoPartVal(Val)); // two instrs.
2486+
UseCP = (ARM_AM::getSOImmVal(Val) == -1 && // MOV
2487+
ARM_AM::getSOImmVal(~Val) == -1 && // MVN
2488+
!ARM_AM::isSOImmTwoPartVal(Val) && // two instrs.
2489+
!(Subtarget->hasV6T2Ops() && Val <= 0xffff)); // MOVW
24882490
}
24892491

24902492
if (UseCP) {
@@ -2494,7 +2496,7 @@ SDNode *ARMDAGToDAGISel::Select(SDNode *N) {
24942496
getTargetLowering()->getPointerTy());
24952497

24962498
SDNode *ResNode;
2497-
if (Subtarget->isThumb1Only()) {
2499+
if (Subtarget->isThumb()) {
24982500
SDValue Pred = getAL(CurDAG);
24992501
SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
25002502
SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };

‎llvm/lib/Target/ARM/ARMInstrInfo.td

+1-1
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ def so_imm2part : PatLeaf<(imm), [{
593593
/// arm_i32imm - True for +V6T2, or true only if so_imm2part is true.
594594
///
595595
def arm_i32imm : PatLeaf<(imm), [{
596-
if (Subtarget->hasV6T2Ops())
596+
if (Subtarget->useMovt())
597597
return true;
598598
return ARM_AM::isSOImmTwoPartVal((unsigned)N->getZExtValue());
599599
}]>;

‎llvm/lib/Target/ARM/ARMInstrThumb2.td

+1-1
Original file line numberDiff line numberDiff line change
@@ -3781,7 +3781,7 @@ def t2SUBS_PC_LR : T2I <(outs), (ins imm0_255:$imm), NoItinerary,
37813781
let isReMaterializable = 1, isMoveImm = 1 in
37823782
def t2MOVi32imm : PseudoInst<(outs rGPR:$dst), (ins i32imm:$src), IIC_iMOVix2,
37833783
[(set rGPR:$dst, (i32 imm:$src))]>,
3784-
Requires<[IsThumb, HasV6T2]>;
3784+
Requires<[IsThumb, UseMovt]>;
37853785

37863786
// Pseudo instruction that combines movw + movt + add pc (if pic).
37873787
// It also makes it possible to rematerialize the instructions.

‎llvm/test/CodeGen/ARM/minsize-imms.ll

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
; RUN: llc -mtriple=thumbv7m-macho -o - -show-mc-encoding %s | FileCheck %s
2+
; RUN: llc -mtriple=thumbv6m-macho -o - -show-mc-encoding %s | FileCheck %s --check-prefix=CHECK-V6M
3+
; RUN: llc -mtriple=armv6-macho -o - -show-mc-encoding %s | FileCheck %s --check-prefix=CHECK-ARM
4+
define i32 @test_mov() minsize {
5+
; CHECK-LABEL: test_mov:
6+
; CHECK: movs r0, #255 @ encoding: [0xff,0x20]
7+
8+
ret i32 255
9+
}
10+
11+
define i32 @test_mov_mvn() minsize {
12+
; CHECK-LABEL: test_mov_mvn:
13+
; CHECK: mvn r0, #203 @ encoding: [0x6f,0xf0,0xcb,0x00]
14+
15+
; CHECK-V6M-LABEL: test_mov_mvn:
16+
; CHECK-V6M: movs [[TMP:r[0-7]]], #203 @ encoding: [0xcb,0x20]
17+
; CHECK-V6M: mvns r0, [[TMP]] @ encoding: [0xc0,0x43]
18+
19+
; CHECK-ARM-LABEL: test_mov_mvn:
20+
; CHECK-ARM: mvn r0, #203 @ encoding: [0xcb,0x00,0xe0,0xe3]
21+
ret i32 4294967092
22+
}
23+
24+
define i32 @test_mov_lsl() minsize {
25+
; CHECK-LABEL: test_mov_lsl:
26+
; CHECK: mov.w r0, #589824 @ encoding: [0x4f,0xf4,0x10,0x20]
27+
28+
; CHECK-V6M-LABEL: test_mov_lsl:
29+
; CHECK-V6M: movs [[TMP:r[0-7]]], #9 @ encoding: [0x09,0x20]
30+
; CHECK-V6M: lsls r0, [[TMP]], #16 @ encoding: [0x00,0x04]
31+
32+
; CHECK-ARM-LABEL: test_mov_lsl:
33+
; CHECK-ARM: mov r0, #589824 @ encoding: [0x09,0x08,0xa0,0xe3]
34+
ret i32 589824
35+
}
36+
37+
define i32 @test_movw() minsize {
38+
; CHECK-LABEL: test_movw:
39+
; CHECK: movw r0, #65535
40+
41+
; CHECK-V6M-LABEL: test_movw:
42+
; CHECK-V6M: ldr r0, [[CONSTPOOL:LCPI[0-9]+_[0-9]+]] @ encoding: [A,0x48]
43+
; CHECK-V6M: [[CONSTPOOL]]:
44+
; CHECK-V6M-NEXT: .long 65535
45+
46+
; CHECK-ARM-LABEL: test_movw:
47+
; CHECK-ARM: mov r0, #255 @ encoding: [0xff,0x00,0xa0,0xe3]
48+
; CHECK-ARM: orr r0, r0, #65280 @ encoding: [0xff,0x0c,0x80,0xe3]
49+
ret i32 65535
50+
}
51+
52+
define i32 @test_regress1() {
53+
; CHECK-ARM-LABEL: test_regress1:
54+
; CHECK-ARM: mov r0, #248 @ encoding: [0xf8,0x00,0xa0,0xe3]
55+
; CHECK-ARM: orr r0, r0, #16252928 @ encoding: [0x3e,0x07,0x80,0xe3]
56+
ret i32 16253176
57+
}

0 commit comments

Comments
 (0)