summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/APInt.cpp
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-05-17 06:26:29 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-05-17 06:26:29 +0000
commitfffdf105669c629333ce928bbf055cdf0815d1c8 (patch)
treeba4b461b08c056714e16ec3162730e623e0fcc9e /llvm/lib/Support/APInt.cpp
parent2648effb23292ac493181ba64dae8241d6da88e2 (diff)
downloadbcm5719-llvm-fffdf105669c629333ce928bbf055cdf0815d1c8.tar.gz
bcm5719-llvm-fffdf105669c629333ce928bbf055cdf0815d1c8.zip
For lshr by 0 bits, just return *this as a short cut. This also prevents
undefined behavior when the width > 64 bits. llvm-svn: 37153
Diffstat (limited to 'llvm/lib/Support/APInt.cpp')
-rw-r--r--llvm/lib/Support/APInt.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index 460cf557610..2ed9b07f1ea 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -1149,6 +1149,12 @@ APInt APInt::lshr(uint32_t shiftAmt) const {
if (shiftAmt == BitWidth)
return APInt(BitWidth, 0);
+ // If none of the bits are shifted out, the result is *this. This avoids
+ // issues with shifting byt he size of the integer type, which produces
+ // undefined results in the code below. This is also an optimization.
+ if (shiftAmt == 0)
+ return *this;
+
// Create some space for the result.
uint64_t * val = new uint64_t[getNumWords()];
OpenPOWER on IntegriCloud