Skip to content

Commit 4a1b357

Browse files
committed
[ARM][LowOverheadLoops] Use tBcc when reverting
Check the branch target ranges and use a tBcc instead of t2Bcc when we can. Differential Revision: https://reviews.llvm.org/D67796 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@372557 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent c481cce commit 4a1b357

File tree

5 files changed

+16
-13
lines changed

5 files changed

+16
-13
lines changed

lib/Target/ARM/ARMLowOverheadLoops.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,7 @@ bool ARMLowOverheadLoops::ProcessLoop(MachineLoop *ML) {
354354

355355
// WhileLoopStart holds the exit block, so produce a cmp lr, 0 and then a
356356
// beq that branches to the exit branch.
357-
// FIXME: Need to check that we're not trashing the CPSR when generating the
358-
// cmp. We could also try to generate a cbz if the value in LR is also in
357+
// TODO: We could also try to generate a cbz if the value in LR is also in
359358
// another low register.
360359
void ARMLowOverheadLoops::RevertWhile(MachineInstr *MI) const {
361360
LLVM_DEBUG(dbgs() << "ARM Loops: Reverting to cmp: " << *MI);
@@ -366,9 +365,12 @@ void ARMLowOverheadLoops::RevertWhile(MachineInstr *MI) const {
366365
MIB.addImm(0);
367366
MIB.addImm(ARMCC::AL);
368367
MIB.addReg(ARM::NoRegister);
368+
369+
MachineBasicBlock *DestBB = MI->getOperand(1).getMBB();
370+
unsigned BrOpc = BBUtils->isBBInRange(MI, DestBB, 254) ?
371+
ARM::tBcc : ARM::t2Bcc;
369372

370-
// TODO: Try to use tBcc instead
371-
MIB = BuildMI(*MBB, MI, MI->getDebugLoc(), TII->get(ARM::t2Bcc));
373+
MIB = BuildMI(*MBB, MI, MI->getDebugLoc(), TII->get(BrOpc));
372374
MIB.add(MI->getOperand(1)); // branch target
373375
MIB.addImm(ARMCC::EQ); // condition code
374376
MIB.addReg(ARM::CPSR);
@@ -391,8 +393,6 @@ void ARMLowOverheadLoops::RevertLoopDec(MachineInstr *MI) const {
391393
}
392394

393395
// Generate a subs, or sub and cmp, and a branch instead of an LE.
394-
// FIXME: Need to check that we're not trashing the CPSR when generating
395-
// the cmp.
396396
void ARMLowOverheadLoops::RevertLoopEnd(MachineInstr *MI) const {
397397
LLVM_DEBUG(dbgs() << "ARM Loops: Reverting to cmp, br: " << *MI);
398398

@@ -405,9 +405,12 @@ void ARMLowOverheadLoops::RevertLoopEnd(MachineInstr *MI) const {
405405
MIB.addImm(ARMCC::AL);
406406
MIB.addReg(ARM::NoRegister);
407407

408-
// TODO Try to use tBcc instead.
408+
MachineBasicBlock *DestBB = MI->getOperand(1).getMBB();
409+
unsigned BrOpc = BBUtils->isBBInRange(MI, DestBB, 254) ?
410+
ARM::tBcc : ARM::t2Bcc;
411+
409412
// Create bne
410-
MIB = BuildMI(*MBB, MI, MI->getDebugLoc(), TII->get(ARM::t2Bcc));
413+
MIB = BuildMI(*MBB, MI, MI->getDebugLoc(), TII->get(BrOpc));
411414
MIB.add(MI->getOperand(1)); // branch target
412415
MIB.addImm(ARMCC::NE); // condition code
413416
MIB.addReg(ARM::CPSR);

test/CodeGen/Thumb2/LowOverheadLoops/branch-targets.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
; CHECK-END: .LBB0_2:
1717
; CHECK-END: sub.w lr, lr, #1
1818
; CHECK-END: cmp.w lr, #0
19-
; CHECK-END: bne.w .LBB0_3
19+
; CHECK-END: bne .LBB0_3
2020
; CHECK-END: b .LBB0_4
2121
; CHECK-END: .LBB0_3:
2222
; CHECK-END: b .LBB0_2

test/CodeGen/Thumb2/LowOverheadLoops/end-positive-offset.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# CHECK-NOT: DLS
55
# CHECK: bb.1.for.body:
66
# CHECK: t2CMPri $lr, 0, 14, $noreg, implicit-def $cpsr
7-
# CHECK: t2Bcc %bb.3, 1, $cpsr
7+
# CHECK: tBcc %bb.3, 1, $cpsr
88
# CHECK: tB %bb.2, 14, $noreg
99
# CHECK: bb.2.for.cond.cleanup:
1010
# CHECK: bb.3.for.header:

test/CodeGen/Thumb2/LowOverheadLoops/revert-non-header.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# CHECK: bb.5.for.inc16:
44
# CHECK: $lr = t2SUBri killed renamable $lr, 1, 14
55
# CHECK: t2CMPri $lr, 0, 14
6-
# CHECK: t2Bcc %bb.6, 1
6+
# CHECK: tBcc %bb.6, 1
77
# CHECK: tB %bb.2
88
# CHECK: bb.6.for.cond4.preheader:
99

test/CodeGen/Thumb2/LowOverheadLoops/revert-non-loop.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
# CHECK: tBcc %bb.2, 3
66
# CHECK: bb.1.not.preheader:
77
# CHECK: t2CMPri renamable $lr, 0, 14
8-
# CHECK: t2Bcc %bb.4, 0
8+
# CHECK: tBcc %bb.4, 0
99
# CHECK: tB %bb.2
1010
# CHECK: bb.3.while.body:
1111
# CHECK: t2CMPri $lr, 0, 14
12-
# CHECK: t2Bcc %bb.3, 1
12+
# CHECK: tBcc %bb.3, 1
1313
# CHECK: tB %bb.4
1414
# CHECK: bb.4.while.end:
1515

0 commit comments

Comments
 (0)