leave uncodnitional fall-through branches in llc -O0

Currently SelectionDAGBuilder::visitBr() doesn’t emit unconditional fall-through branches (to next block) without reference of optimization level. So the following LLVM IR


br label %return, !dbg !26

return: ; preds = %entry

ret void, !dbg !27

has no generated DAG node for “br” instruction. If we are going to generate debug line table for this branch in -O0 mode, we should leave it in place. For example such a branch can be generated by a FE for some “return;” statement at the end of void function or for one of “break;” statement if switch-related exit block is next to BB of the “break;”.

This change emits all unconditional branches in -O0 mode:

— lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

+++ lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

@@ -1584,8 +1584,8 @@ void SelectionDAGBuilder::visitBr(const BranchInst

// Update machine-CFG edges.


  • // If this is not a fall-through branch, emit the branch.

  • if (Succ0MBB != NextBlock)

  • // If this is not a fall-through branch or optimizations are off

  • if (Succ0MBB != NextBlock || CodeGenOpt::None == TM.getOptLevel())

DAG.setRoot(DAG.getNode(ISD::BR, getCurSDLoc(),

MVT::Other, getControlRoot(),




emit_uncond_br.patch (669 Bytes)