}
// Record this immediate branch.
- unsigned MaxOffs = (1 << (Bits-1)) * Scale;
+ unsigned MaxOffs = ((1 << (Bits-1))-1) * Scale;
ImmBranches.push_back(ImmBranch(I, MaxOffs, isCond, UOpc));
}
DEBUG(std::cerr << "User of CPE#" << CPEMI->getOperand(0).getImm()
<< " max delta=" << MaxDisp
- << " at offset " << int(UserOffset-CPEOffset) << "\t"
+ << " at offset " << int(CPEOffset-UserOffset) << "\t"
<< *MI);
if (UserOffset <= CPEOffset) {
unsigned DestOffset = GetOffsetOf(DestBB);
DEBUG(std::cerr << "Branch of destination BB#" << DestBB->getNumber()
+ << " from BB#" << MI->getParent()->getNumber()
<< " max delta=" << MaxDisp
- << " at offset " << int(BrOffset-DestOffset) << "\t"
+ << " at offset " << int(DestOffset-BrOffset) << "\t"
<< *MI);
if (BrOffset <= DestOffset) {
BBSizes[MBB->getNumber()] += 2;
HasFarJump = true;
NumUBrFixed++;
+
+ DEBUG(std::cerr << " Changed B to long jump " << *MI);
+
return true;
}
// direct the updated conditional branch to the fall-through block. Otherwise,
// split the MBB before the next instruction.
MachineBasicBlock *MBB = MI->getParent();
- MachineInstr *BackMI = &MBB->back();
- bool NeedSplit = (BackMI != MI) || !BBHasFallthrough(MBB);
+ MachineInstr *BMI = &MBB->back();
+ bool NeedSplit = (BMI != MI) || !BBHasFallthrough(MBB);
NumCBrFixed++;
- if (BackMI != MI) {
+ if (BMI != MI) {
if (next(MachineBasicBlock::iterator(MI)) == MBB->back() &&
- BackMI->getOpcode() == Br.UncondBr) {
+ BMI->getOpcode() == Br.UncondBr) {
// Last MI in the BB is a unconditional branch. Can we simply invert the
// condition and swap destinations:
// beq L1
// =>
// bne L2
// b L1
- MachineBasicBlock *NewDest = BackMI->getOperand(0).getMachineBasicBlock();
+ MachineBasicBlock *NewDest = BMI->getOperand(0).getMachineBasicBlock();
if (BBIsInRange(MI, NewDest, Br.MaxDisp)) {
- BackMI->getOperand(0).setMachineBasicBlock(DestBB);
+ DEBUG(std::cerr << " Invert Bcc condition and swap its destination"
+ << " with " << *BMI);
+
+ BMI->getOperand(0).setMachineBasicBlock(DestBB);
MI->getOperand(0).setMachineBasicBlock(NewDest);
MI->getOperand(1).setImm(CC);
return true;
MBB->back().eraseFromParent();
}
MachineBasicBlock *NextBB = next(MachineFunction::iterator(MBB));
+
+ DEBUG(std::cerr << " Insert B to BB#" << DestBB->getNumber()
+ << " also invert condition and change dest. to BB#"
+ << NextBB->getNumber() << "\n");
// Insert a unconditional branch and replace the conditional branch.
// Also update the ImmBranch as well as adding a new entry for the new branch.