Ensure SplitEdge to return the new block between the two given blocks
authorWhitney Tsang <whitneyt@ca.ibm.com>
Fri, 18 Dec 2020 17:35:46 +0000 (17:35 +0000)
committerWhitney Tsang <whitneyt@ca.ibm.com>
Fri, 18 Dec 2020 17:37:17 +0000 (17:37 +0000)
commit2a814cd9e1e8493c6606712d55f9ffdb58396481
tree2b34e1179470bffbda8be255d091b7e5e9bd27a8
parentce94e7d867abf5c08f5b0008f2d31b3f169b815d
Ensure SplitEdge to return the new block between the two given blocks

This PR implements the function splitBasicBlockBefore to address an
issue
that occurred during SplitEdge(BB, Succ, ...), inside splitBlockBefore.
The issue occurs in SplitEdge when the Succ has a single predecessor
and the edge between the BB and Succ is not critical. This produces
the result ‘BB->Succ->New’. The new function splitBasicBlockBefore
was added to splitBlockBefore to handle the issue and now produces
the correct result ‘BB->New->Succ’.

Below is an example of splitting the block bb1 at its first instruction.

/// Original IR
bb0:
br bb1
bb1:
        %0 = mul i32 1, 2
br bb2
bb2:
/// IR after splitEdge(bb0, bb1) using splitBasicBlock
bb0:
br bb1
bb1:
br bb1.split
bb1.split:
        %0 = mul i32 1, 2
br bb2
bb2:
/// IR after splitEdge(bb0, bb1) using splitBasicBlockBefore
bb0:
br bb1.split
bb1.split
br bb1
bb1:
        %0 = mul i32 1, 2
br bb2
bb2:

Differential Revision: https://reviews.llvm.org/D92200
llvm/include/llvm/IR/BasicBlock.h
llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
llvm/lib/IR/BasicBlock.cpp
llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
llvm/test/CodeGen/AMDGPU/call-constexpr.ll
llvm/test/Transforms/LoopUnswitch/2011-11-18-SimpleSwitch.ll
llvm/unittests/Transforms/Utils/BasicBlockUtilsTest.cpp