[Mlir-commits] [mlir] [MLIR][Vector] Fix WarpOpScfForOp and WarpOpScfIfOp leaving invalid ops after region moves (PR #188951)
Kunwar Grover
llvmlistbot at llvm.org
Wed Apr 15 06:58:41 PDT 2026
================
@@ -2009,6 +2011,26 @@ struct WarpOpScfIfOp : public WarpDistributionPattern {
for (auto [origIdx, newIdx] : ifResultMapping)
rewriter.replaceAllUsesExcept(newWarpOp.getResult(origIdx),
newIfOp.getResult(newIdx), newIfOp);
+
+ // The original `ifOp` was left inside `newWarpOp` with empty then/else
+ // regions (their blocks were moved into the inner WarpOps by takeBody).
+ // Clear remaining uses and erase it to restore IR validity. Directly
+ // update newWarpOp's yield operands instead of using replaceAllUsesWith,
+ // to avoid triggering notifyOperandReplaced on the now-invalid ifOp.
+ {
+ OpBuilder::InsertionGuard guard(rewriter);
+ rewriter.setInsertionPoint(ifOp);
+ Operation *yield = newWarpOp.getTerminator();
+ rewriter.modifyOpInPlace(yield, [&]() {
+ for (auto [origIdx, ifResultIdx] : ifResultMapping) {
+ Value poison = ub::PoisonOp::create(
+ rewriter, ifOp.getLoc(), ifOp.getResult(ifResultIdx).getType());
+ yield->setOperand(origIdx, poison);
+ }
+ });
+ rewriter.eraseOp(ifOp);
+ }
----------------
Groverkss wrote:
Then bit before already replaces all uses. do we need to replace all these uses? Can we not just erase the op?
https://github.com/llvm/llvm-project/pull/188951
More information about the Mlir-commits
mailing list