[llvm] r260447 - APInt: Simplify EqualSlowCase
Duncan P. N. Exon Smith via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 14 13:25:33 PST 2016
> On 2016-Feb-10, at 14:13, Matthias Braun via llvm-commits <llvm-commits at lists.llvm.org> wrote:
>
> Author: matze
> Date: Wed Feb 10 16:13:10 2016
> New Revision: 260447
>
> URL: http://llvm.org/viewvc/llvm-project?rev=260447&view=rev
> Log:
> 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
>
> Modified:
> llvm/trunk/lib/Support/APInt.cpp
>
> Modified: llvm/trunk/lib/Support/APInt.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APInt.cpp?rev=260447&r1=260446&r2=260447&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Support/APInt.cpp (original)
> +++ llvm/trunk/lib/Support/APInt.cpp Wed Feb 10 16:13:10 2016
> @@ -490,21 +490,8 @@ APInt APInt::operator-(const APInt& RHS)
> }
>
> 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;
I think at this point it seems equivalent to:
```
return std::equal(pVal, pVal + getNumWords(), RHS.pVal);
```
> }
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list