[Mlir-commits] [mlir] [MLIR] [Mem2Reg] Quick fix for dominance info invalidation (PR #188518)

Théo Degioanni llvmlistbot at llvm.org
Wed Mar 25 08:52:51 PDT 2026


https://github.com/tdegioanni-nvidia created https://github.com/llvm/llvm-project/pull/188518

We have identified a problem with DominanceInfo caching in Mem2Reg. It appears to also be subject to incorrect cache hits when regions are deleted, causing sporadic bugs that are difficult to test for.

This quick fix invalidates region that could be invalidated. This attempts to not be too eager by only invalidating regions that are exposed to a `finalizePromotion` call.

Ultimately it would be nice to have the ability to move the cached information from one region to the next, but this is currently not supported by DominanceInfo.

I was not able to produce a test for this as it is very sporadic. We would need to be testing for a case where a region is re-allocated at the same address as a previously erased region. If you know how to make this sort of behavior consistent, I would be interested. Otherwise this might require no testing.

>From 8a3c4b2f526934a578d6fe2e68a657eb9d8ac92a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Th=C3=A9o=20Degioanni?= <tdegioanni at nvidia.com>
Date: Wed, 25 Mar 2026 15:45:03 +0000
Subject: [PATCH] quick fix for dominance info invalidation

---
 mlir/lib/Transforms/Mem2Reg.cpp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/mlir/lib/Transforms/Mem2Reg.cpp b/mlir/lib/Transforms/Mem2Reg.cpp
index 5bd0c70f1d33f..1e76d38508165 100644
--- a/mlir/lib/Transforms/Mem2Reg.cpp
+++ b/mlir/lib/Transforms/Mem2Reg.cpp
@@ -608,6 +608,13 @@ Value MemorySlotPromoter::promoteInBlock(Block *block, Value reachingDef) {
           promoteInRegion(region, reachingDef);
         }
 
+        // TODO: Currently we have to invalidate the dominance information of
+        // the regions of the operation because finalizePromotion may move their
+        // content. We might want to support moving dominance information
+        // accross regions as this can be detected.
+        for (Region &region : op->getRegions())
+          dominance.invalidate(&region);
+
         builder.setInsertionPointAfter(op);
         reachingDef = promotableRegionOp.finalizePromotion(
             slot, reachingDef, hasValueStores, reachingAtBlockEnd, builder);



More information about the Mlir-commits mailing list