[PATCH] D69960: [ConstantRange] Add `ushl_sat()`/`sshl_sat()` methods.
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 7 12:50:30 PST 2019
nikic added a comment.
> Unlike ConstantRange::shl(), these are precise.
At least when modelling the APInt semantics. If we treat too large shifts as poison, then we could produce empty sets in more cases. But this seems like a reasonable starting point...
================
Comment at: llvm/lib/IR/ConstantRange.cpp:1359
+ NewU = getSignedMax().sshl_sat(Other.getUnsignedMax()) + 1;
+ }
+ return getNonEmpty(std::move(NewL), std::move(NewU));
----------------
Wondering if a formulation along the lines of
```
APInt Min = getSignedMin(), Max = getSignedMax();
APInt ShiftMin = getUnsignedMin(), ShiftMax = getUnsignedMax();
APInt NewL = Min.sshl_sat(Min.isNonNegative() ? ShiftMin : ShiftMax);
APInt NewU = Max.sshl_sat(Max.isNonNegative() ? ShiftMax : ShiftMin) + 1;
```
might be cleaner?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D69960/new/
https://reviews.llvm.org/D69960
More information about the llvm-commits
mailing list