diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2007-05-12 18:01:57 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2007-05-12 18:01:57 +0000 |
commit | 81ee020f649a5f18f7e2c969fa4ed81c34e19f1f (patch) | |
tree | 74b03eb2c62588a0f999bff65dac09a9200ba3b7 /llvm/lib/Support/APInt.cpp | |
parent | 5d22b630afb3a6106607a07d0b35cd55a5142eb3 (diff) | |
download | bcm5719-llvm-81ee020f649a5f18f7e2c969fa4ed81c34e19f1f.tar.gz bcm5719-llvm-81ee020f649a5f18f7e2c969fa4ed81c34e19f1f.zip |
Fix shl to produce the correct result when the bitwidth is > 64 and the
shift amount is 0. Previously this code would do a lshr by the bit width
which can lead to incorrect results.
llvm-svn: 37010
Diffstat (limited to 'llvm/lib/Support/APInt.cpp')
-rw-r--r-- | llvm/lib/Support/APInt.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index 4142c6ec8bc..2a35aa057ef 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -1199,6 +1199,12 @@ APInt APInt::shl(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 a + // lshr by the words size in the loop below which can produce incorrect + // results. It also avoids the expensive computation below for a common case. + if (shiftAmt == 0) + return *this; + // Create some space for the result. uint64_t * val = new uint64_t[getNumWords()]; |