[Mlir-commits] [mlir] Enable LICM for ops with only read side effects in scf.for (PR #120302)

donald chen llvmlistbot at llvm.org
Thu Dec 26 04:43:47 PST 2024


================
@@ -306,6 +306,26 @@ bool mlir::wouldOpBeTriviallyDead(Operation *op) {
   return wouldOpBeTriviallyDeadImpl(op);
 }
 
+bool mlir::hasOnlyReadEffect(Operation *op) {
+  if (auto memEffects = dyn_cast<MemoryEffectOpInterface>(op)) {
+    if (!op->hasTrait<OpTrait::HasRecursiveMemoryEffects>())
+      return memEffects.onlyHasEffect<MemoryEffects::Read>();
+  } else if (!op->hasTrait<OpTrait::HasRecursiveMemoryEffects>()) {
+    // Otherwise, if the op does not implement the memory effect interface and
+    // it does not have recursive side effects, then it cannot be known that the
+    // op is moveable.
+    return false;
----------------
cxy-1993 wrote:

This implementation is not robust and can hardly handle any operations with regions, because their terminators are inherently memory effect free.

https://github.com/llvm/llvm-project/pull/120302


More information about the Mlir-commits mailing list