(original) (raw)
Perhaps, you'd need to also check that the block %15 has only one predecessor and has no other users?
Posting the error message might help.
On Thu, Feb 6, 2020 at 8:17 PM Charitha Saumya via llvm-dev <llvm-dev@lists.llvm.org> wrote:
Hi,
I want to remove a redundant unconditional branch from a Function. In the following example I want to remove
br label %26
and merge them to a single basic block.; :9: ; preds = %7 %10 = fadd float %5, %8 %11 = fmul float %5, %8 %12 = fadd float %10, %11 %13 = fdiv float %5, %8 %14 = fadd float %13, %12 br label %15 ; :15: ; preds = %9 br label %26
I tried to do this as follow but ended up getting runtime error. Can someone help?
Thanks
Charitha
for(auto it1 = F.begin(); it1 != F.end(); it1++){
BasicBlock& bb = *it1;
auto BI = dyn_cast(bb.getTerminator());
if(BI && BI->isUnconditional() && bb.size() == 1){
for (BasicBlock *pred : predecessors(&bb)) {
auto predBI = dyn_cast(pred->getTerminator());
if(predBI && predBI->isUnconditional()){
predBI->setSuccessor(0, bb.getSingleSuccessor());
BI->dropAllReferences();
BI->removeFromParent();
}
}
}
}
_______________________________________________
LLVM Developers mailing list
llvm-dev@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev