Index: lib/Target/Mips/MipsDelaySlotFiller.cpp =================================================================== --- lib/Target/Mips/MipsDelaySlotFiller.cpp +++ lib/Target/Mips/MipsDelaySlotFiller.cpp @@ -62,6 +62,24 @@ cl::desc("Disallow MIPS delay filler to search backward."), cl::Hidden); +enum CompactBranchPolicy { + CBNever, + CBOptimal, + CBAlways +}; + +static cl::opt MipsCompactBranchPolicy( + "mips-compact-branches",cl::Optional, + cl::init(CBOptimal), + cl::desc("MIPS Specific: Compact branch policy."), + cl::values( + clEnumValN(CBNever, "never", "Do not use compact branches if possible."), + clEnumValN(CBOptimal, "optimal", "Use compact branches where appropiate (default)."), + clEnumValN(CBAlways, "always", "Always use compact branches if possible."), + clEnumValEnd + ) +); + namespace { typedef MachineBasicBlock::iterator Iter; typedef MachineBasicBlock::reverse_iterator ReverseIter; @@ -563,14 +581,17 @@ if (!DisableDelaySlotFiller && (TM.getOptLevel() != CodeGenOpt::None)) { bool Filled = false; - if (searchBackward(MBB, I)) { - Filled = true; - } else if (I->isTerminator()) { - if (searchSuccBBs(MBB, I)) { + if (MipsCompactBranchPolicy.getValue() != CBAlways || + !TII->getEquivalentCompactForm(I)) { + if (searchBackward(MBB, I)) { + Filled = true; + } else if (I->isTerminator()) { + if (searchSuccBBs(MBB, I)) { + Filled = true; + } + } else if (searchForward(MBB, I)) { Filled = true; } - } else if (searchForward(MBB, I)) { - Filled = true; } if (Filled) { @@ -596,8 +617,9 @@ // For MIPSR6 attempt to produce the corresponding compact (no delay slot) // form of the CTI. For indirect jumps this will not require inserting a // NOP and for branches will hopefully avoid requiring a NOP. - if ((InMicroMipsMode || STI.hasMips32r6()) && - TII->getEquivalentCompactForm(I)) { + if ((InMicroMipsMode || + (STI.hasMips32r6() && MipsCompactBranchPolicy != CBNever)) && + TII->getEquivalentCompactForm(I)) { I = replaceWithCompactBranch(MBB, I, I->getDebugLoc()); continue; } Index: test/CodeGen/Mips/compactbranches/compact-branch-policy.ll =================================================================== --- /dev/null +++ test/CodeGen/Mips/compactbranches/compact-branch-policy.ll @@ -0,0 +1,26 @@ +; Check that -mips-compact-branches={never,optimal,always} is accepted and honoured. +; RUN: llc -march=mips -mcpu=mips32r6 -mips-compact-branches=never < %s | FileCheck %s -check-prefix=NEVER +; RUN: llc -march=mips -mcpu=mips32r6 -mips-compact-branches=optimal < %s | FileCheck %s -check-prefix=OPTIMAL +; RUN: llc -march=mips -mcpu=mips32r6 -mips-compact-branches=always < %s | FileCheck %s -check-prefix=ALWAYS + +define i32 @l(i32 signext %a, i32 signext %b) { +entry: + %add = add nsw i32 %b, %a + %cmp = icmp slt i32 %add, 100 +; NEVER: beq +; OPTIMAL: beq +; ALWAYS: beqzc +; ALWAYS: nop + br i1 %cmp, label %if.then, label %if.end + +if.then: ; preds = %entry + %call = tail call i32 @k() + br label %if.end + +if.end: ; preds = %entry, %if.then + %call.pn = phi i32 [ %call, %if.then ], [ -1, %entry ] + %c.0 = add nsw i32 %call.pn, %add + ret i32 %c.0 +} + +declare i32 @k() #1