diff options
author | Marcello Maggioni <hayarms@gmail.com> | 2019-04-07 06:12:44 +0000 |
---|---|---|
committer | Marcello Maggioni <hayarms@gmail.com> | 2019-04-07 06:12:44 +0000 |
commit | 30eb5758112a7f972d4ffea4ed0aa5f1c2732b40 (patch) | |
tree | e4f923b30450506d856638fc42247906e4f7388e /llvm/lib/IR/ConstantRange.cpp | |
parent | 545ed223a65513475203f81f267bf1656b8f4e04 (diff) | |
download | bcm5719-llvm-30eb5758112a7f972d4ffea4ed0aa5f1c2732b40.tar.gz bcm5719-llvm-30eb5758112a7f972d4ffea4ed0aa5f1c2732b40.zip |
[ConstantRange] Shl considers full-set shifting to last bit position.
if we do SHL of two 16-bit ranges like [0, 30000) with [1,2) we get
"full-set" instead of what I would have expected [0, 60000) which is
still in the 16-bit unsigned range.
This patch changes the SHL algorithm to allow getting a usable range
even in this case.
Differential Revision: https://reviews.llvm.org/D57983
llvm-svn: 357854
Diffstat (limited to 'llvm/lib/IR/ConstantRange.cpp')
-rw-r--r-- | llvm/lib/IR/ConstantRange.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp index eda31f73473..f07ec9d5a3f 100644 --- a/llvm/lib/IR/ConstantRange.cpp +++ b/llvm/lib/IR/ConstantRange.cpp @@ -1006,8 +1006,12 @@ ConstantRange::shl(const ConstantRange &Other) const { APInt max = getUnsignedMax(); APInt Other_umax = Other.getUnsignedMax(); + // If we are shifting by maximum amount of + // zero return return the original range. + if (Other_umax.isNullValue()) + return *this; // there's overflow! - if (Other_umax.uge(max.countLeadingZeros())) + if (Other_umax.ugt(max.countLeadingZeros())) return getFull(); // FIXME: implement the other tricky cases |