[mlir][Standard] Add a canonicalization to simplify cond_br when the successors are identical
This revision adds support for canonicalizing the following: ``` cond_br %cond, ^bb1(A, ..., N), ^bb1(A, ..., N) br ^bb1(A, ..., N) ``` If the operands to the successor are different and the cond_br is the only predecessor, we emit selects for the branch operands. ``` cond_br %cond, ^bb1(A), ^bb1(B) %select = select %cond, A, B br ^bb1(%select) ``` Differential Revision: https://reviews.llvm.org/D78682
This commit is contained in:
@@ -229,6 +229,21 @@ Block *Block::getSinglePredecessor() {
|
||||
return it == pred_end() ? firstPred : nullptr;
|
||||
}
|
||||
|
||||
/// If this block has a unique predecessor, i.e., all incoming edges originate
|
||||
/// from one block, return it. Otherwise, return null.
|
||||
Block *Block::getUniquePredecessor() {
|
||||
auto it = pred_begin(), e = pred_end();
|
||||
if (it == e)
|
||||
return nullptr;
|
||||
|
||||
// Check for any conflicting predecessors.
|
||||
auto *firstPred = *it;
|
||||
for (++it; it != e; ++it)
|
||||
if (*it != firstPred)
|
||||
return nullptr;
|
||||
return firstPred;
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Other
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
Reference in New Issue
Block a user