[Mlir-commits] [mlir] [mlir] Optimize `isOpTriviallyDead` greedy rewriter checks for deeply nested IR (PR #231423)
Ivan Butygin
llvmlistbot at llvm.org
Mon Oct 26 06:00:11 PDT 2026
================
@@ -66,49 +99,93 @@ static bool wouldOpBeTriviallyDeadImpl(Operation *rootOp) {
}
}
- // If the op has memory effects, try to characterize them to see if the op
- // is trivially dead here.
- if (auto effectInterface = dyn_cast<MemoryEffectOpInterface>(op)) {
- // Check to see if this op either has no effects, or only allocates/reads
- // memory.
- SmallVector<MemoryEffects::EffectInstance, 1> effects;
- effectInterface.getEffects(effects);
+ if (!hasOnlyDeadEffects(op, hasRecursiveEffects))
+ return false;
+ }
- // Gather all results of this op that are allocated.
- SmallPtrSet<Value, 4> allocResults;
- for (const MemoryEffects::EffectInstance &it : effects)
- if (isa<MemoryEffects::Allocate>(it.getEffect()) && it.getValue() &&
- it.getValue().getDefiningOp() == op)
- allocResults.insert(it.getValue());
-
- if (!llvm::all_of(effects, [&allocResults](
- const MemoryEffects::EffectInstance &it) {
- // We can drop effects if the value is an allocation and is a result
- // of the operation.
- if (allocResults.contains(it.getValue()))
- return true;
- // Otherwise, the effect must be a read.
- return isa<MemoryEffects::Read>(it.getEffect());
- })) {
- return false;
- }
+ // If we get here, none of the operations had effects that prevented marking
+ // 'op' as dead.
+ return true;
+}
+
+bool DeadnessCache::isOpTriviallyDead(Operation *root) {
----------------
Hardcode84 wrote:
done
https://github.com/llvm/llvm-project/pull/231423
More information about the Mlir-commits
mailing list