llvm.org GIT mirror llvm / 676084e
[ARM] Allow rematerialization of ARM Thumb literal pool loads Constants are crucial for code size in the ARM Thumb-1 instruction set. The 16 bit instruction size often does not offer enough space for immediate arguments. This means that additional instructions are frequently used to load constants into registers. Since constants are hoisted, this can lead to significant register spillage if they are used multiple times in a single function. This can be avoided by rematerialization, i.e. recomputing a constant instead of reloading it from the stack. This patch fixes the rematerialization of literal pool loads in the ARM Thumb instruction set. Patch by Philip Ginsbach Differential Revision: https://reviews.llvm.org/D33936 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@308004 91177308-0d34-0410-b5e6-96231b3b80d8 Sam Parker 3 years ago
3 changed file(s) with 47 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
26812681
26822682 SDNode *ResNode;
26832683 if (Subtarget->isThumb()) {
2684 SDValue Pred = getAL(CurDAG, dl);
2685 SDValue PredReg = CurDAG->getRegister(0, MVT::i32);
2686 SDValue Ops[] = { CPIdx, Pred, PredReg, CurDAG->getEntryNode() };
2684 SDValue Ops[] = {
2685 CPIdx,
2686 getAL(CurDAG, dl),
2687 CurDAG->getRegister(0, MVT::i32),
2688 CurDAG->getEntryNode()
2689 };
26872690 ResNode = CurDAG->getMachineNode(ARM::tLDRpci, dl, MVT::i32, MVT::Other,
26882691 Ops);
26892692 } else {
26972700 ResNode = CurDAG->getMachineNode(ARM::LDRcp, dl, MVT::i32, MVT::Other,
26982701 Ops);
26992702 }
2703 // Annotate the Node with memory operand information so that MachineInstr
2704 // queries work properly. This e.g. gives the register allocation the
2705 // required information for rematerialization.
2706 MachineFunction& MF = CurDAG->getMachineFunction();
2707 MachineSDNode::mmo_iterator MemOp = MF.allocateMemRefsArray(1);
2708 MemOp[0] = MF.getMachineMemOperand(
2709 MachinePointerInfo::getConstantPool(MF),
2710 MachineMemOperand::MOLoad, 4, 4);
2711
2712 cast(ResNode)->setMemRefs(MemOp, MemOp+1);
2713
27002714 ReplaceNode(N, ResNode);
27012715 return;
27022716 }
0 ; RUN: llc < %s -mtriple=thumb-apple-darwin | FileCheck %s
1
2 declare void @consume_value(i32) #1
3
4 declare i32 @get_value(...) #1
5
6 declare void @consume_three_values(i32, i32, i32) #1
7
8 ; Function Attrs: nounwind uwtable
9 define void @should_not_spill() #0 {
10 tail call void @consume_value(i32 1764) #2
11 %1 = tail call i32 (...) @get_value() #2
12 %2 = tail call i32 (...) @get_value() #2
13 %3 = tail call i32 (...) @get_value() #2
14 tail call void @consume_value(i32 %1) #2
15 tail call void @consume_value(i32 %2) #2
16 tail call void @consume_value(i32 %3) #2
17 tail call void @consume_value(i32 1764) #2
18 tail call void @consume_three_values(i32 %1, i32 %2, i32 %3) #2
19 ret void
20 }
21
22 ; CHECK: ldr r0, LCPI0_0
23 ; CHECK-NOT: str r0
24 ; CHECK: bl
25 ; CHECK: ldr r0, LCPI0_0
26 ; CHECK-LABEL: LCPI0_0:
27 ; CHECK-NEXT: .long 1764
7373 }
7474 ; CHECK-LABEL: f7:
7575 ; CHECK: blt
76 ; CHECK: blt
76 ; CHECK: {{blt|bge}}
7777 ; CHECK: __ltdf2
7878 ; CHECK-EABI-LABEL: f7:
7979 ; CHECK-EABI: __aeabi_dcmplt
8080 ; CHECK-EABI: bne
81 ; CHECK-EABI: bne
81 ; CHECK-EABI: {{bne|beq}}