Index: lib/Target/Mips/MicroMipsInstrFormats.td =================================================================== --- lib/Target/Mips/MicroMipsInstrFormats.td +++ lib/Target/Mips/MicroMipsInstrFormats.td @@ -621,3 +621,15 @@ let Inst{10-6} = fr; let Inst{5-0} = funct; } + +class COMPACT_BRANCH_FM_MM funct> { + bits<5> rs; + bits<16> offset; + + bits<32> Inst; + + let Inst{31-26} = 0x10; + let Inst{25-21} = funct; + let Inst{20-16} = rs; + let Inst{15-0} = offset; +} Index: lib/Target/Mips/MicroMipsInstrInfo.td =================================================================== --- lib/Target/Mips/MicroMipsInstrInfo.td +++ lib/Target/Mips/MicroMipsInstrInfo.td @@ -26,6 +26,16 @@ let DecoderMethod = "DecodeBranchTargetMM"; } +class CompactBranchMM : + InstSE<(outs), (ins RO:$rs, opnd:$offset), + !strconcat(opstr, "\t$rs, $offset"), [], IIBranch, FrmI> { + let isBranch = 1; + let isTerminator = 1; + let hasDelaySlot = 0; + let Defs = [AT]; +} + let canFoldAsLoad = 1 in class LoadLeftRightMM : @@ -104,6 +114,12 @@ NoItinerary, FrmOther, opstr>; let DecoderNamespace = "MicroMips", Predicates = [InMicroMips] in { + /// Compact Branch Instructions + def BEQZC_MM : CompactBranchMM<"beqzc", brtarget_mm, seteq, GPR32Opnd>, + COMPACT_BRANCH_FM_MM<0x7>; + def BNEZC_MM : CompactBranchMM<"bnezc", brtarget_mm, setne, GPR32Opnd>, + COMPACT_BRANCH_FM_MM<0x5>; + /// Arithmetic Instructions (ALU Immediate) def ADDiu_MM : MMRel, ArithLogicI<"addiu", simm16, GPR32Opnd>, ADDI_FM_MM<0xc>; Index: test/MC/Mips/micromips-compact-branch-instructions.s =================================================================== --- /dev/null +++ test/MC/Mips/micromips-compact-branch-instructions.s @@ -0,0 +1,21 @@ +# RUN: llvm-mc %s -triple=mipsel -show-encoding -mattr=micromips | \ +# RUN: FileCheck -check-prefix=CHECK-EL %s +# RUN: llvm-mc %s -triple=mips -show-encoding -mattr=micromips | \ +# RUN: FileCheck -check-prefix=CHECK-EB %s +# Check that the assembler can handle the documented syntax +# for compact branch instructions. +#------------------------------------------------------------------------------ +# MicroMIPS 32-bit Compact Branch Instructions +#------------------------------------------------------------------------------ +# Little endian +#------------------------------------------------------------------------------ +# CHECK-EL: beqzc $9, 1332 # encoding: [0xe9,0x40,0x9a,0x02] +# CHECK-EL: bnezc $9, 1332 # encoding: [0xa9,0x40,0x9a,0x02] +#------------------------------------------------------------------------------ +# Big endian +#------------------------------------------------------------------------------ +# CHECK-EB: beqzc $9, 1332 # encoding: [0x40,0xe9,0x02,0x9a] +# CHECK-EB: bnezc $9, 1332 # encoding: [0x40,0xa9,0x02,0x9a] + + beqzc $9, 1332 + bnezc $9, 1332