diff options
| author | Craig Topper <craig.topper@gmail.com> | 2017-05-09 07:04:04 +0000 |
|---|---|---|
| committer | Craig Topper <craig.topper@gmail.com> | 2017-05-09 07:04:04 +0000 |
| commit | ef02803bedc42abf4e10773587783015b348dbf3 (patch) | |
| tree | 3249d5446648fbb7682742fb09cab0a11efb3a97 /llvm/lib/IR/ConstantRange.cpp | |
| parent | 79b7666f02af974052e2d0340077ed9fd8259dbc (diff) | |
| download | bcm5719-llvm-ef02803bedc42abf4e10773587783015b348dbf3.tar.gz bcm5719-llvm-ef02803bedc42abf4e10773587783015b348dbf3.zip | |
[ConstantRange] Rewrite shl to avoid repeated calls to getUnsignedMax and avoid creating the min APInt until we're sure we need it. Use inplace shift operations.
llvm-svn: 302510
Diffstat (limited to 'llvm/lib/IR/ConstantRange.cpp')
| -rw-r--r-- | llvm/lib/IR/ConstantRange.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp index 6801ed4fb51..a33d062dbea 100644 --- a/llvm/lib/IR/ConstantRange.cpp +++ b/llvm/lib/IR/ConstantRange.cpp @@ -892,16 +892,20 @@ ConstantRange::shl(const ConstantRange &Other) const { if (isEmptySet() || Other.isEmptySet()) return ConstantRange(getBitWidth(), /*isFullSet=*/false); - APInt min = getUnsignedMin().shl(Other.getUnsignedMin()); - APInt max = getUnsignedMax().shl(Other.getUnsignedMax()); + APInt max = getUnsignedMax(); + APInt Other_umax = Other.getUnsignedMax(); - // there's no overflow! - APInt Zeros(getBitWidth(), getUnsignedMax().countLeadingZeros()); - if (Zeros.ugt(Other.getUnsignedMax())) - return ConstantRange(std::move(min), std::move(max) + 1); + // there's overflow! + if (Other_umax.uge(max.countLeadingZeros())) + return ConstantRange(getBitWidth(), /*isFullSet=*/true); // FIXME: implement the other tricky cases - return ConstantRange(getBitWidth(), /*isFullSet=*/true); + + APInt min = getUnsignedMin(); + min <<= Other.getUnsignedMin(); + max <<= Other_umax; + + return ConstantRange(std::move(min), std::move(max) + 1); } ConstantRange |

