[llvm] ValueTracking: Use SimplifyQuery for computeConstantRange (PR #191726)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 19 10:52:50 PDT 2026


================
@@ -1,5 +1,8 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals all --version 5
-; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+; RUN: opt < %s -passes='instcombine<no-verify-fixpoint>' -S | FileCheck %s
+
+; no-verify-fixpoint is necessary due to dropping nuw, and then
----------------
dtcxzyw wrote:

It is caused by the out-of-date AC result. In the second iteration, the assumption gets visited first, and the affected values are updated.

The following patch should address this issue:
```diff
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 6798493de1aa..96c129a431de 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -5360,8 +5360,22 @@ bool InstCombinerImpl::freezeOtherUses(FreezeInst &FI) {
     Changed = true;
   }
 
+  SmallVector<User *> Users;
   Changed |= Op->replaceUsesWithIf(
-      &FI, [&](Use &U) -> bool { return DT.dominates(&FI, U); });
+      &FI, [&](Use &U) -> bool { if (!DT.dominates(&FI, U))
+          return false;
+
+      Users.push_back(U.getUser());
+      return true;
+    });
+
+  for (auto *U : Users) {
+    for (auto &AssumeVH : AC.assumptionsFor(U)) {
+      if (!AssumeVH)
+        continue;
+      AC.updateAffectedValues(cast<AssumeInst>(AssumeVH));
+    }
+  }
 
   return Changed;
 }
```

TBH AC should always be updated when the operands are changed (especially in `replaceInstUsesWith`). But I guess it may cause significant compile-time overhead...


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


More information about the llvm-commits mailing list