@@ -354,8 +354,7 @@ bool ARMLowOverheadLoops::ProcessLoop(MachineLoop *ML) {
354
354
355
355
// WhileLoopStart holds the exit block, so produce a cmp lr, 0 and then a
356
356
// 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
359
358
// another low register.
360
359
void ARMLowOverheadLoops::RevertWhile (MachineInstr *MI) const {
361
360
LLVM_DEBUG (dbgs () << " ARM Loops: Reverting to cmp: " << *MI);
@@ -366,9 +365,12 @@ void ARMLowOverheadLoops::RevertWhile(MachineInstr *MI) const {
366
365
MIB.addImm (0 );
367
366
MIB.addImm (ARMCC::AL);
368
367
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;
369
372
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));
372
374
MIB.add (MI->getOperand (1 )); // branch target
373
375
MIB.addImm (ARMCC::EQ); // condition code
374
376
MIB.addReg (ARM::CPSR);
@@ -391,8 +393,6 @@ void ARMLowOverheadLoops::RevertLoopDec(MachineInstr *MI) const {
391
393
}
392
394
393
395
// 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.
396
396
void ARMLowOverheadLoops::RevertLoopEnd (MachineInstr *MI) const {
397
397
LLVM_DEBUG (dbgs () << " ARM Loops: Reverting to cmp, br: " << *MI);
398
398
@@ -405,9 +405,12 @@ void ARMLowOverheadLoops::RevertLoopEnd(MachineInstr *MI) const {
405
405
MIB.addImm (ARMCC::AL);
406
406
MIB.addReg (ARM::NoRegister);
407
407
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
+
409
412
// Create bne
410
- MIB = BuildMI (*MBB, MI, MI->getDebugLoc (), TII->get (ARM::t2Bcc ));
413
+ MIB = BuildMI (*MBB, MI, MI->getDebugLoc (), TII->get (BrOpc ));
411
414
MIB.add (MI->getOperand (1 )); // branch target
412
415
MIB.addImm (ARMCC::NE); // condition code
413
416
MIB.addReg (ARM::CPSR);
0 commit comments