Octeon branches (bbit0/bbit032/bbit1/bbit132) have an immediate operand, so it is legal to have such replacement within MipsBranchExpansion::replaceBranch().
According to the specification, a branch (e.g. bbit0 ) looks like:
bbit0 rs p offset // p is an immediate operand if !rs<p> then branch
Without this patch, an assertion triggers in the method, and the problem has been found in the real example.
This might be more cleanly expressed as a switch statement over the kind of operand, e.g.
switch (MO.getKind()) { case MachineOperand::MO_Register: MIB.addReg(MO.getReg(); continue; case MachineOperand::MO_Immediate: if (!TII->isBranchWithImm(Br->getOpcode())) llvm_unreachable("Unexpected immediate in branch instruction!"); MIB.addImm(MO.getImm()); continue; case MachineOperand::MO_MachineBasicBlock: MIB.addMBB(MO); break; default: llvm_unreachable("Unknown operand kind in MipsBranchExpansion::replaceBranch(..)!"); } break;What do you think? You'll also move line 360 into the loop.