[llvm] r302769 - [SCEV] Reduce possible APInt allocations a bit.

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Mon May 15 09:37:13 PDT 2017


On Thu, May 11, 2017 at 12:02 AM Craig Topper via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: ctopper
> Date: Thu May 11 01:48:54 2017
> New Revision: 302769
>
> URL: http://llvm.org/viewvc/llvm-project?rev=302769&view=rev
> Log:
> [SCEV] Reduce possible APInt allocations a bit.
>
> Modified:
>     llvm/trunk/lib/Analysis/ScalarEvolution.cpp
>
> Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=302769&r1=302768&r2=302769&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
> +++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Thu May 11 01:48:54 2017
> @@ -7377,15 +7377,18 @@ SolveQuadraticEquation(const SCEVAddRecE
>    const APInt &N = NC->getAPInt();
>    APInt Two(BitWidth, 2);
>
> -  const APInt& C = L;
>    // Convert from chrec coefficients to polynomial coefficients AX^2+BX+C
> -  // The B coefficient is M-N/2
> -  APInt B(M);
> -  B -= N.sdiv(Two);
>
>    // The A coefficient is N/2
>    APInt A(N.sdiv(Two));
>
> +  // The B coefficient is M-N/2
> +  APInt B(M);
>

Prefer copy init over direct init:

  APInt B = M;

That way it's clear to the reader that no explicit (ie: more
powerful/possibly riskier) conversion is occurring here. (similarly
elsewhere in this patch & otherwise)


> +  B -= A; // A is the same as N/2.
> +
> +  // The C coefficient is L.
> +  const APInt& C = L;
> +
>    // Compute the B^2-4ac term.
>    APInt SqrtTerm(B);
>    SqrtTerm *= B;
> @@ -7402,9 +7405,10 @@ SolveQuadraticEquation(const SCEVAddRecE
>
>    // Compute the two solutions for the quadratic formula.
>    // The divisions must be performed as signed divisions.
> -  APInt NegB(-B);
> -  APInt TwoA(A << 1);
> -  if (TwoA.isMinValue())
> +  APInt NegB(-std::move(B));
> +  APInt TwoA(std::move(A));
> +  TwoA <<= 1;
> +  if (TwoA.isNullValue())
>      return None;
>
>    LLVMContext &Context = SE.getContext();
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170515/1a310c15/attachment.html>


More information about the llvm-commits mailing list