File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -308,9 +308,22 @@ bool mlir::wouldOpBeTriviallyDead(Operation *op) {
308308
309309bool mlir::hasOnlyReadEffect (Operation *op) {
310310 if (auto memEffects = dyn_cast<MemoryEffectOpInterface>(op)) {
311- return memEffects.onlyHasEffect <MemoryEffects::Read>();
311+ if (!op->hasTrait <OpTrait::HasRecursiveMemoryEffects>())
312+ return memEffects.onlyHasEffect <MemoryEffects::Read>();
313+ } else if (!op->hasTrait <OpTrait::HasRecursiveMemoryEffects>()) {
314+ // Otherwise, if the op does not implement the memory effect interface and
315+ // it does not have recursive side effects, then it cannot be known that the
316+ // op is moveable.
317+ return false ;
312318 }
313- return false ;
319+
320+ // Recurse into the regions and ensure that all nested ops are memory effect
321+ // free.
322+ for (Region ®ion : op->getRegions ())
323+ for (Operation &op : region.getOps ())
324+ if (!hasOnlyReadEffect (&op))
325+ return false ;
326+ return true ;
314327}
315328
316329bool mlir::isMemoryEffectFree (Operation *op) {
Original file line number Diff line number Diff line change @@ -139,7 +139,7 @@ size_t mlir::moveLoopInvariantCode(
139139 !canBeHoisted (op, definedOutside))
140140 continue ;
141141 // Can only hoist pure ops (side-effect free) when there is an op with
142- // write side effects in the loop.
142+ // write and/or unknown side effects in the loop.
143143 if (!loopSideEffectFreeOrHasOnlyReadSideEffect && !isMemoryEffectFree (op))
144144 continue ;
145145
You can’t perform that action at this time.
0 commit comments