From: Nick Lewycky Date: Tue, 6 Sep 2011 05:33:18 +0000 (+0000) Subject: Fix flipped sign. While there, show my math. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=28682ae00f6d6f71c325de2b1d80c0b7a8df0716;p=oota-llvm.git Fix flipped sign. While there, show my math. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@139135 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index c64cdf89ccb..9f8b5c5dfe5 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -1976,7 +1976,13 @@ const SCEV *ScalarEvolution::getMulExpr(SmallVectorImpl &Ops, OtherIdx < Ops.size() && isa(Ops[OtherIdx]); ++OtherIdx) if (AddRecLoop == cast(Ops[OtherIdx])->getLoop()) { - // {A,+,B} * {C,+,D} --> {A*C,+,A*D + B*C + B*D,+,2*B*D} + // {A,+,B} * {C,+,D} --> {A*C,+,A*D + B*C - B*D,+,2*B*D} + // + // For reference, given that {X,+,Y,+,Z} = x + y*It + z*It^2 then + // X = x, Y = y-z, Z = 2z. + // + // x = A*C, y = (A*D + B*C), z = B*D + // Therefore X = A*C, Y = (A*D + B*C) - B*D and Z = 2*B*D. for (; OtherIdx != Ops.size() && isa(Ops[OtherIdx]); ++OtherIdx) if (const SCEVAddRecExpr *OtherAddRec = @@ -1989,7 +1995,8 @@ const SCEV *ScalarEvolution::getMulExpr(SmallVectorImpl &Ops, const SCEV *NewStart = getMulExpr(A, C); const SCEV *BD = getMulExpr(B, D); const SCEV *NewStep = getAddExpr(getMulExpr(A, D), - getMulExpr(B, C), BD); + getMulExpr(B, C), + getNegativeSCEV(BD)); const SCEV *NewSecondOrderStep = getMulExpr(BD, getConstant(BD->getType(), 2));