[Mlir-commits] [mlir] [MLIR][Conversion] Remove func dialect dependency for CF to SCF conversion (PR #222594)
Tobias Gysi
llvmlistbot at llvm.org
Thu Sep 10 05:42:32 PDT 2026
================
@@ -421,15 +421,35 @@ class ReturnLikeExitCombiner {
/// Transforms `returnLikeOp` to a branch to the only block in the
/// region with an instance of `returnLikeOp`s kind.
void combineExit(Operation *returnLikeOp,
- function_ref<Value(unsigned)> getSwitchValue) {
- auto [iter, inserted] = returnLikeToCombinedExit.try_emplace(returnLikeOp);
- if (!inserted && iter->first == returnLikeOp)
+ function_ref<Value(unsigned)> getSwitchValue,
+ function_ref<Value(Type)> getUndefValue) {
+ auto existing = returnLikeToCombinedExit.find(returnLikeOp);
+ if (existing != returnLikeToCombinedExit.end() &&
+ existing->first == returnLikeOp)
return;
+ // If `returnLikeOp` is an unreachable terminator and an exit block of
+ // another return-like operation already exists, it is turned into a branch
+ // to that exit block with undefined operands instead of getting an exit
+ // block of its own.
+ if (interface.isUnreachableTerminator(returnLikeOp) &&
+ !orderedExitBlocks.empty()) {
+ Block *exitBlock = orderedExitBlocks.front();
+ auto builder = OpBuilder::atBlockTerminator(returnLikeOp->getBlock());
+ interface.createSingleDestinationBranch(
+ returnLikeOp->getLoc(), builder, getSwitchValue(0), exitBlock,
+ llvm::map_to_vector(exitBlock->getArgumentTypes(), getUndefValue));
----------------
gysit wrote:
nit: it could make sense to rename `getUndefValue` to `getPoisonValue`. It seems like it changed from producing undef to producing poison at some time but the helper itself was never renamed.
https://github.com/llvm/llvm-project/pull/222594
More information about the Mlir-commits
mailing list