[Mlir-commits] [mlir] Add operands to worklist when only used by deleted op (PR #86990)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Mar 28 15:45:33 PDT 2024
================
@@ -688,15 +688,17 @@ void GreedyPatternRewriteDriver::notifyOperationModified(Operation *op) {
addToWorklist(op);
}
-void GreedyPatternRewriteDriver::addOperandsToWorklist(ValueRange operands) {
- for (Value operand : operands) {
- // If the use count of this operand is now < 2, we re-add the defining
- // operation to the worklist.
- // TODO: This is based on the fact that zero use operations
- // may be deleted, and that single use values often have more
- // canonicalization opportunities.
- if (!operand || (!operand.use_empty() && !operand.hasOneUse()))
- continue;
+void GreedyPatternRewriteDriver::addOperandsToWorklist(Operation* op) {
+ for (Value operand : op->getOperands()) {
+ // If this operand was only used by the op under consideration, we re-add
+ // the operation that defined it to the worklist. Indeed, if the op is about
+ // to be deleted and it was the sole user of the operand, the operand may
+ // also be deleted.
+ // TODO: if the operand has a single use besides the op under consideration,
+ // there may be further canonicalization opportunities, so it should be
+ // added to the worklist.
+ if (!operand) continue;
+ if (!llvm::all_of(operand.getUsers(), [&op](auto u) { return u == op; })) continue;
----------------
mlevesquedion wrote:
Actually, nevermind. I thought `mlir::Value` had `hasOneUser`, but that's `llvm::Value`. I believe there would be a more efficient way to do this (https://github.com/llvm/llvm-project/blob/44af53b22aaa1fe382b22329bbc7e4610ecbacc8/llvm/lib/IR/Value.cpp#L157), but the users list doesn't seem to be deduped, so just doing `std::next(user_begin()) == user_end()` does not work.
https://github.com/llvm/llvm-project/pull/86990
More information about the Mlir-commits
mailing list