diff options
author | Matthias Braun <matze@braunis.de> | 2016-02-10 22:13:10 +0000 |
---|---|---|
committer | Matthias Braun <matze@braunis.de> | 2016-02-10 22:13:10 +0000 |
commit | 936db8fa2f20a99596c16e209df37f1c29041844 (patch) | |
tree | 183c72d42afd75fd436a82d82c2073641011f317 /llvm/lib/Support/APInt.cpp | |
parent | f54827f1b8488111bd40bb9124c0f484624944fa (diff) | |
download | llvm-936db8fa2f20a99596c16e209df37f1c29041844.zip llvm-936db8fa2f20a99596c16e209df37f1c29041844.tar.gz llvm-936db8fa2f20a99596c16e209df37f1c29041844.tar.bz2 |
APInt: Simplify EqualSlowCase
Previously the code used getActiveBits() to determine the highest set
bit of each APInt first. However doing so requires the same amount of
memory accesses as simply comparing both numbers right away.
Removing all the active bit checks leads to simpler code and is faster
in my benchmark.
Differential Revision: http://reviews.llvm.org/D16620
llvm-svn: 260447
Diffstat (limited to 'llvm/lib/Support/APInt.cpp')
-rw-r--r-- | llvm/lib/Support/APInt.cpp | 17 |
1 files changed, 2 insertions, 15 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index b150baf..af95aad 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -490,21 +490,8 @@ APInt APInt::operator-(const APInt& RHS) const { } bool APInt::EqualSlowCase(const APInt& RHS) const { - // Get some facts about the number of bits used in the two operands. - unsigned n1 = getActiveBits(); - unsigned n2 = RHS.getActiveBits(); - - // If the number of bits isn't the same, they aren't equal - if (n1 != n2) - return false; - - // If the number of bits fits in a word, we only need to compare the low word. - if (n1 <= APINT_BITS_PER_WORD) - return pVal[0] == RHS.pVal[0]; - - // Otherwise, compare everything - for (int i = whichWord(n1 - 1); i >= 0; --i) - if (pVal[i] != RHS.pVal[i]) + for (unsigned I = 0, NumWords = getNumWords(); I < NumWords; ++I) + if (pVal[I] != RHS.pVal[I]) return false; return true; } |