[llvm-dev] Removing a redundant unconditional branch (original) (raw)

Hiroshi Yamauchi via llvm-dev llvm-dev at lists.llvm.org
Fri Feb 7 08:59:04 PST 2020


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 at 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 = dyncast(bb.getTerminator()); if(BI && BI->isUnconditional() && bb.size() == 1){ for (BasicBlock *pred : predecessors(&bb)) { auto predBI = dyncast(pred->getTerminator()); if(predBI && predBI->isUnconditional()){ predBI->setSuccessor(0, bb.getSingleSuccessor()); BI->dropAllReferences(); BI->removeFromParent(); } } } }


LLVM Developers mailing list llvm-dev at lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200207/828fc8e3/attachment.html>



More information about the llvm-dev mailing list