Index: llvm/lib/Target/Mips/MipsBranchExpansion.cpp =================================================================== --- llvm/lib/Target/Mips/MipsBranchExpansion.cpp +++ llvm/lib/Target/Mips/MipsBranchExpansion.cpp @@ -343,7 +343,14 @@ MachineOperand &MO = Br->getOperand(I); if (!MO.isReg()) { - assert(MO.isMBB() && "MBB operand expected."); + // Octeon branches "On bit clear/clear plus 32/set/set plus 32" + // have an immidiate operand (e.g. BBIT0 $v0, 3, %bb.1). + if (MO.isImm() && TII->isBranchWithImm(Br->getOpcode())) { + MIB.addImm(MO.getImm()); + continue; + } else { + assert(MO.isMBB() && "MBB operand expected."); + } break; } Index: llvm/lib/Target/Mips/MipsInstrInfo.h =================================================================== --- llvm/lib/Target/Mips/MipsInstrInfo.h +++ llvm/lib/Target/Mips/MipsInstrInfo.h @@ -106,6 +106,10 @@ virtual unsigned getOppositeBranchOpc(unsigned Opc) const = 0; + virtual bool isBranchWithImm(unsigned Opc) const { + return false; + } + /// Return the number of bytes of code the specified instruction may be. unsigned getInstSizeInBytes(const MachineInstr &MI) const override; Index: llvm/lib/Target/Mips/MipsSEInstrInfo.h =================================================================== --- llvm/lib/Target/Mips/MipsSEInstrInfo.h +++ llvm/lib/Target/Mips/MipsSEInstrInfo.h @@ -62,6 +62,8 @@ bool expandPostRAPseudo(MachineInstr &MI) const override; + bool isBranchWithImm(unsigned Opc) const override; + unsigned getOppositeBranchOpc(unsigned Opc) const override; /// Adjust SP by Amount bytes. Index: llvm/lib/Target/Mips/MipsSEInstrInfo.cpp =================================================================== --- llvm/lib/Target/Mips/MipsSEInstrInfo.cpp +++ llvm/lib/Target/Mips/MipsSEInstrInfo.cpp @@ -483,6 +483,20 @@ return true; } +/// isBranchWithImm - Return true if the branch contains an immediate +/// operand (\see lib/Target/Mips/MipsBranchExpansion.cpp). +bool MipsSEInstrInfo::isBranchWithImm(unsigned Opc) const { + switch (Opc) { + default: + return false; + case Mips::BBIT0: + case Mips::BBIT1: + case Mips::BBIT032: + case Mips::BBIT132: + return true; + } +} + /// getOppositeBranchOpc - Return the inverse of the specified /// opcode, e.g. turning BEQ to BNE. unsigned MipsSEInstrInfo::getOppositeBranchOpc(unsigned Opc) const { Index: llvm/test/CodeGen/Mips/longbranch/long-branch-octeon.ll =================================================================== --- /dev/null +++ llvm/test/CodeGen/Mips/longbranch/long-branch-octeon.ll @@ -0,0 +1,97 @@ +; RUN: llc -O3 -mtriple=mips64-octeon-linux -mcpu=octeon -force-mips-long-branch < %s -o - | FileCheck %s + +; CHECK-LABEL: bbit1: +; CHECK: %bb.0: +; CHECK-NEXT: bbit0 $4, 3, .LBB0_2 +; CHECK-NEXT: nop +; CHECK-NEXT: %bb.1: +; CHECK-NEXT: j .LBB0_3 +; CHECK-NEXT: nop +; CHECK-NEXT: .LBB0_2: +; CHECK-NEXT: jr $ra +; CHECK: .LBB0_3: +; CHECK-NEXT: jr $ra + +define i64 @bbit1(i64 %a) nounwind { +entry: + %bit = and i64 %a, 8 + %res = icmp eq i64 %bit, 0 + br i1 %res, label %endif, label %if +if: + ret i64 48 + +endif: + ret i64 12 +} + +; CHECK-LABEL: bbit132: +; CHECK: %bb.0: +; CHECK-NEXT: bbit032 $4, 3, .LBB1_2 +; CHECK-NEXT: nop +; CHECK-NEXT: %bb.1: +; CHECK-NEXT: j .LBB1_3 +; CHECK-NEXT: nop +; CHECK-NEXT: .LBB1_2: +; CHECK-NEXT: jr $ra +; CHECK: .LBB1_3: +; CHECK-NEXT: jr $ra + +define i64 @bbit132(i64 %a) nounwind { +entry: + %bit = and i64 %a, 34359738368 + %res = icmp eq i64 %bit, 0 + br i1 %res, label %endif, label %if +if: + ret i64 48 + +endif: + ret i64 12 +} + +; CHECK-LABEL: bbit0: +; CHECK: %bb.0: +; CHECK-NEXT: bbit1 $4, 3, .LBB2_2 +; CHECK-NEXT: nop +; CHECK-NEXT: %bb.1: +; CHECK-NEXT: j .LBB2_3 +; CHECK-NEXT: nop +; CHECK-NEXT: .LBB2_2: +; CHECK-NEXT: jr $ra +; CHECK: .LBB2_3: +; CHECK-NEXT: jr $ra + +define i64 @bbit0(i64 %a) nounwind { +entry: + %bit = and i64 %a, 8 + %res = icmp ne i64 %bit, 0 + br i1 %res, label %endif, label %if +if: + ret i64 48 + +endif: + ret i64 12 +} + +; CHECK-LABEL: bbit032: +; CHECK: %bb.0: +; CHECK-NEXT: bbit132 $4, 3, .LBB3_2 +; CHECK-NEXT: nop +; CHECK-NEXT: %bb.1: +; CHECK-NEXT: j .LBB3_3 +; CHECK-NEXT: nop +; CHECK-NEXT: .LBB3_2: +; CHECK-NEXT: jr $ra +; CHECK: .LBB3_3: +; CHECK-NEXT: jr $ra + +define i64 @bbit032(i64 %a) nounwind { +entry: + %bit = and i64 %a, 34359738368 + %res = icmp ne i64 %bit, 0 + br i1 %res, label %endif, label %if +if: + ret i64 48 + +endif: + ret i64 12 +}