LLVM Regions after SplitEdge


I have the following CFG.

Regions for this CFG are.
[0] entry => if.end12
[1] if.else => if.end

An optimization pass I am working on requires if.then block to be a LLVM region. Therefore I used the SplitEdge function (in BasicBlockUtils) to split the edge if.then → if.end12. Now I have the following CFG,

However my regions are still,
[0] entry => if.end12
[1] if.else => if.end

if.then=>if.then.split is not a region. Can someone explain why this is not a LLVM region? It’s a single entry single exit control flow. Why is it not a region?

Also what is the correct way to recalculate LLVM regions after modifying the controlflow?

Following approach gave me a runtime error when run on the function after splitting the if.then → if.end12 ,

RegionInfo &RI = getAnalysis().getRegionInfo();
DominatorTree &DT = getAnalysis().getDomTree();
DominanceFrontier &DF = getAnalysis().getDominanceFrontier();
PostDominatorTree &PDT = getAnalysis().getPostDomTree();

RI.recalculate(F, &DT, &PDT, &DF);

Runtime error,

Stack dump:
0. Program arguments: /home/charitha/workspace/llvm_install/bin/opt -load /home/charitha/workspace/llvm-project/build/lib/LLVMCFMerger.so -cfmerger -view-cfg-only

  1. Running pass ‘Function Pass Manager’ on module ‘’.
  2. Running pass ‘Merge similar control flow for divergence reduction’ on function ‘@foo
    #0 0x000056094798307a llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/home/charitha/workspace/llvm_install/bin/opt+0x299407a)
    #1 0x0000560947980df4 llvm::sys::RunSignalHandlers() (/home/charitha/workspace/llvm_install/bin/opt+0x2991df4)
    #2 0x0000560947980f43 SignalHandler(int) (/home/charitha/workspace/llvm_install/bin/opt+0x2991f43)
    #3 0x00007fc487be33c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
    #4 0x0000560946b7a6a0 llvm::RegionInfoBase<llvm::RegionTraitsllvm::Function >::isRegion(llvm::BasicBlock*, llvm::BasicBlock*) const