[llvm] [ValueTracking] Try to infer range of select from true and false values. (PR #68256)
Mikhail Gudim via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 5 06:58:59 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);
----------------
mgudim wrote:
@goldsteinn Maybe I didn't understand what you mean. But I tried the following test without my patch:
```
define i1 @foo(i32 %x) {
entry:
%cmp0_ = icmp ule i32 %x, 10
%select_ = select i1 %cmp0_, i32 %x, i32 10
%cmp1_ = icmp ule i32 %select_, 10
ret i1 %cmp1_
}
```
This simplifies to:
```
define i1 @foo(i32 %x) {
entry:
ret i1 true
}
```
I put a print statement right after a call to `setLimitsForSelectPattern(*SI, Lower, Upper, IIQ)`, the return range is `[0, 11)`.
Can you please demonstrate what's missing with another test case?
https://github.com/llvm/llvm-project/pull/68256
More information about the llvm-commits
mailing list