[LLVMdev] Splitting a basic block, replacing it's terminator

Nick Johnson npjohnso at cs.princeton.edu
Fri May 8 16:02:54 PDT 2009


I want to insert a conditional branch in the middle of a basic block.
To that end, I am doing these steps:

(1) Split the basic block:

(2) Remove the old terminator:

(3) Adding a new terminator:
 BranchInst::Create(ifTrue, ifFalse, cnd, "", bb);

That seems to work, but later passes are dieing.  When I dump the
function from my debugger, I notice that the new block (the second
half of the block I split) has a "<null operand>" as a predecessor.
What am I doing wrong?

Here's what bb->getParent()->dump shows.  bb4.preheader is the
original basic block; bb4.preheader.noExit is the block created by the
splitBasicBlock() operation:

bb4.preheader:          ; preds = %bb5, %preheader
      ; blah blah blah
        %6 = icmp slt i32 %timestamp, 0         ; <i1> [#uses=1]
        br i1 %6, label %__mtcg_sync_to_bb7.loopexit, label

bb4.preheader.noExit:           ; preds = %bb4.preheader, <null operand!>
     ; blah blah blah
        br i1 %10, label %bb5, label %bb1

Nick Johnson

More information about the llvm-dev mailing list