[Mlir-commits] [mlir] 4df44c4 - [mlir] Only treat "Alloc" effects as dead if they are for operation results.
River Riddle
llvmlistbot at llvm.org
Sat Mar 14 13:57:38 PDT 2020
Author: River Riddle
Date: 2020-03-14T13:53:56-07:00
New Revision: 4df44c4f9c0f07109eadcf0032a817da2f37151e
URL: https://github.com/llvm/llvm-project/commit/4df44c4f9c0f07109eadcf0032a817da2f37151e
DIFF: https://github.com/llvm/llvm-project/commit/4df44c4f9c0f07109eadcf0032a817da2f37151e.diff
LOG: [mlir] Only treat "Alloc" effects as dead if they are for operation results.
Allocate could be used for an "output" of an operation in the case of buffer-style operations.
Added:
Modified:
mlir/lib/Interfaces/SideEffects.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Interfaces/SideEffects.cpp b/mlir/lib/Interfaces/SideEffects.cpp
index 53406c6e8b32..aa670d591a0a 100644
--- a/mlir/lib/Interfaces/SideEffects.cpp
+++ b/mlir/lib/Interfaces/SideEffects.cpp
@@ -63,9 +63,13 @@ static bool wouldOpBeTriviallyDeadImpl(Operation *rootOp) {
// memory.
SmallVector<MemoryEffects::EffectInstance, 1> effects;
effectInterface.getEffects(effects);
- if (!llvm::all_of(effects, [](const auto &it) {
- return isa<MemoryEffects::Read>(it.getEffect()) ||
- isa<MemoryEffects::Allocate>(it.getEffect());
+ if (!llvm::all_of(effects, [op](const MemoryEffects::EffectInstance &it) {
+ // We can drop allocations if the value is a result of the
+ // operation.
+ if (isa<MemoryEffects::Allocate>(it.getEffect()))
+ return it.getValue() && it.getValue().getDefiningOp() == op;
+ // Otherwise, the effect must be a read.
+ return isa<MemoryEffects::Read>(it.getEffect());
})) {
return false;
}
More information about the Mlir-commits
mailing list