[Mlir-commits] [mlir] [MLIR][SideEffects][MemoryEffects] Modified LICM to be more aggressive when checking movability of ops with MemWrite effects (PR #155344)

Uday Bondhugula llvmlistbot at llvm.org
Thu Dec 11 22:36:06 PST 2025


================
@@ -317,14 +319,45 @@ bool mlir::wouldOpBeTriviallyDead(Operation *op) {
   return wouldOpBeTriviallyDeadImpl(op);
 }
 
+llvm::SmallVector<MemoryEffects::EffectInstance>
+mlir::MemoryEffects::getMemoryEffectsSorted(Operation *op) {
+  llvm::SmallVector<MemoryEffects::EffectInstance> effectsSorted;
+
+  auto memInterface = dyn_cast<MemoryEffectOpInterface>(op);
+
+  if (!memInterface)
+    return effectsSorted; // return empty vec
+
+  memInterface.getEffects(effectsSorted);
+
+  auto sortEffects =
+      [](llvm::SmallVectorImpl<MemoryEffects::EffectInstance> &effects) {
+        llvm::stable_sort(effects, [](const MemoryEffects::EffectInstance &a,
+                                      const MemoryEffects::EffectInstance &b) {
+          if (a.getStage() < b.getStage())
+            return true;
+
+          if (a.getStage() == b.getStage())
+            return a.getEffect()->getPriority() < b.getEffect()->getPriority();
+
+          return false; // b before a
----------------
bondhugula wrote:

Avoid trailing comments. Terminate comments with a period.

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


More information about the Mlir-commits mailing list