[llvm] [InstCombine] Create a class to lazily track computed known bits (PR #66611)

via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 11 15:26:45 PDT 2023


================
@@ -6251,12 +6251,13 @@ static OverflowResult mapOverflowResult(ConstantRange::OverflowResult OR) {
 
 /// Combine constant ranges from computeConstantRange() and computeKnownBits().
 static ConstantRange computeConstantRangeIncludingKnownBits(
-    const Value *V, bool ForSigned, const DataLayout &DL, AssumptionCache *AC,
-    const Instruction *CxtI, const DominatorTree *DT,
+    const CachedBitsConstValue &V, bool ForSigned, const DataLayout &DL,
+    AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT,
     bool UseInstrInfo = true) {
-  KnownBits Known =
-      computeKnownBits(V, DL, /*Depth=*/0, AC, CxtI, DT, UseInstrInfo);
-  ConstantRange CR1 = ConstantRange::fromKnownBits(Known, ForSigned);
+  ConstantRange CR1 = ConstantRange::fromKnownBits(
+      V.getKnownBits(SimplifyQuery(DL, /*TLI*/ nullptr, DT, AC,
+                                   safeCxtI(V, CxtI), UseInstrInfo)),
+      ForSigned);
----------------
goldsteinn wrote:

You might just add an API for `getCR()` in the same vein is `getKnownBits` For now it can just do the above logic, but we might want to cache that someday as well. Also seems to fit.

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


More information about the llvm-commits mailing list