diff options
author | Mikhail Gudim <mgudim@gmail.com> | 2023-10-05 13:23:05 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-05 13:23:05 -0400 |
commit | 4a2a6a4111035b4ccd0dce9e6445006f003b88e3 (patch) | |
tree | 5101e6301fc841ada8595804bcdc4620aefb6960 /llvm/lib/Analysis | |
parent | 67955033fde0518305d1291edc1ee1cfebb986d0 (diff) | |
download | llvm-4a2a6a4111035b4ccd0dce9e6445006f003b88e3.zip llvm-4a2a6a4111035b4ccd0dce9e6445006f003b88e3.tar.gz llvm-4a2a6a4111035b4ccd0dce9e6445006f003b88e3.tar.bz2 |
[ValueTracking] Try to infer range of select from true and false values. (#68256)
When computing range of `select` instruction, first compute the union of
ranges of "True" and "False" operands of the `select` instruction.
Diffstat (limited to 'llvm/lib/Analysis')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index b76becf..f5b1878 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -8841,9 +8841,14 @@ ConstantRange llvm::computeConstantRange(const Value *V, bool ForSigned, CR = ConstantRange::getNonEmpty(Lower, Upper); } else if (auto *II = dyn_cast<IntrinsicInst>(V)) CR = getRangeForIntrinsic(*II); - else if (auto *SI = dyn_cast<SelectInst>(V)) - CR = getRangeForSelectPattern(*SI, IIQ); - else if (isa<FPToUIInst>(V) || isa<FPToSIInst>(V)) { + 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); + CR = CR.intersectWith(getRangeForSelectPattern(*SI, IIQ)); + } else if (isa<FPToUIInst>(V) || isa<FPToSIInst>(V)) { APInt Lower = APInt(BitWidth, 0); APInt Upper = APInt(BitWidth, 0); // TODO: Return ConstantRange. |