[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.
This commit is contained in:
River Riddle 2020-03-14 13:50:01 -07:00
parent 43959a2592
commit 4df44c4f9c
1 changed files with 7 additions and 3 deletions

View File

@ -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;
}