[llvm] [LVI] Merge ranges reliably and precisely (PR #173714)

Kunqiu Chen via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 30 08:31:41 PST 2025


================
@@ -741,27 +986,32 @@ LazyValueInfoImpl::solveBlockValueNonLocal(Value *Val, BasicBlock *BB) {
   std::optional<BBLatticeElementMap> PredLatticeElements;
   if (PerPredRanges)
     PredLatticeElements = std::make_optional<BBLatticeElementMap>();
-  for (BasicBlock *Pred : predecessors(BB)) {
-    // Skip self loops.
-    if (Pred == BB)
-      continue;
-    std::optional<ValueLatticeElement> EdgeResult = getEdgeValue(Val, Pred, BB);
-    if (!EdgeResult)
-      // Explore that input, then return here
-      return std::nullopt;
 
-    Result.mergeIn(*EdgeResult);
+  {
+    ValueLatticeMerger Merger(Result);
+    for (BasicBlock *Pred : predecessors(BB)) {
+      // Skip self loops.
+      if (Pred == BB)
+        continue;
+      std::optional<ValueLatticeElement> EdgeResult =
+          getEdgeValue(Val, Pred, BB);
+      if (!EdgeResult)
+        // Explore that input, then return here
+        return std::nullopt;
+
+      Merger.mergeIn(*EdgeResult);
----------------
Camsyn wrote:

Is it necessary to manage to extend this change to SCCP as well?
The monotonicity of the merge function is a sufficient, but not a necessary, condition for the convergence of fixpoint iteration.

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


More information about the llvm-commits mailing list