[llvm] [ValueTracking] Try to infer range of select from true and false values. (PR #68256)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 5 07:02:17 PDT 2023


================
@@ -8854,11 +8854,16 @@ ConstantRange llvm::computeConstantRange(const Value *V, bool ForSigned,
   } else if (auto *II = dyn_cast<IntrinsicInst>(V))
     CR = getRangeForIntrinsic(*II);
   else if (auto *SI = dyn_cast<SelectInst>(V)) {
+    ConstantRange CRTrue = computeConstantRange(
+        SI->getTrueValue(), ForSigned, UseInstrInfo, AC, CtxI, DT, Depth + 1);
+    ConstantRange CRFalse = computeConstantRange(
+        SI->getFalseValue(), ForSigned, UseInstrInfo, AC, CtxI, DT, Depth + 1);
+    CR = CRTrue.unionWith(CRFalse);
----------------
nikic wrote:

@mgudim I believe the case @goldsteinn has in mind is where it's not a min/max pattern. So e.g. if you do `icmp ule i32 %x, 20` then you know the result is <= 20, but it's not a min/max pattern.

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


More information about the llvm-commits mailing list