[llvm] r345813 - [SCEV] Avoid redundant computations when doing AddRec merge
Max Kazantsev via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 31 23:18:27 PDT 2018
Author: mkazantsev
Date: Wed Oct 31 23:18:27 2018
New Revision: 345813
URL: http://llvm.org/viewvc/llvm-project?rev=345813&view=rev
Log:
[SCEV] Avoid redundant computations when doing AddRec merge
When we calculate a product of 2 AddRecs, we end up making quite massive
computations to deduce the operands of resulting AddRec. This process can
be optimized by computing all args of intermediate sum and then calling
`getAddExpr` once rather than calling `getAddExpr` with intermediate
result every time a new argument is computed.
Differential Revision: https://reviews.llvm.org/D53189
Reviewed By: rtereshin
Modified:
llvm/trunk/lib/Analysis/ScalarEvolution.cpp
llvm/trunk/test/Analysis/ScalarEvolution/binomial-explision.ll
Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=345813&r1=345812&r2=345813&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Wed Oct 31 23:18:27 2018
@@ -3060,7 +3060,7 @@ const SCEV *ScalarEvolution::getMulExpr(
SmallVector<const SCEV*, 7> AddRecOps;
for (int x = 0, xe = AddRec->getNumOperands() +
OtherAddRec->getNumOperands() - 1; x != xe && !Overflow; ++x) {
- const SCEV *Term = getZero(Ty);
+ SmallVector <const SCEV *, 7> SumOps;
for (int y = x, ye = 2*x+1; y != ye && !Overflow; ++y) {
uint64_t Coeff1 = Choose(x, 2*x - y, Overflow);
for (int z = std::max(y-x, y-(int)AddRec->getNumOperands()+1),
@@ -3075,12 +3075,13 @@ const SCEV *ScalarEvolution::getMulExpr(
const SCEV *CoeffTerm = getConstant(Ty, Coeff);
const SCEV *Term1 = AddRec->getOperand(y-z);
const SCEV *Term2 = OtherAddRec->getOperand(z);
- Term = getAddExpr(Term, getMulExpr(CoeffTerm, Term1, Term2,
- SCEV::FlagAnyWrap, Depth + 1),
- SCEV::FlagAnyWrap, Depth + 1);
+ SumOps.push_back(getMulExpr(CoeffTerm, Term1, Term2,
+ SCEV::FlagAnyWrap, Depth + 1));
}
}
- AddRecOps.push_back(Term);
+ if (SumOps.empty())
+ SumOps.push_back(getZero(Ty));
+ AddRecOps.push_back(getAddExpr(SumOps, SCEV::FlagAnyWrap, Depth + 1));
}
if (!Overflow) {
const SCEV *NewAddRec = getAddRecExpr(AddRecOps, AddRec->getLoop(),
Modified: llvm/trunk/test/Analysis/ScalarEvolution/binomial-explision.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/ScalarEvolution/binomial-explision.ll?rev=345813&r1=345812&r2=345813&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/ScalarEvolution/binomial-explision.ll (original)
+++ llvm/trunk/test/Analysis/ScalarEvolution/binomial-explision.ll Wed Oct 31 23:18:27 2018
@@ -8,7 +8,7 @@ target datalayout = "e-m:e-i64:64-f80:12
define void @test(i32 %x, i64 %y, i1 %cond) {
; CHECK: %tmp19 = mul i32 %tmp17, %tmp18
-; CHECK: ((((
+; CHECK: ((((((
; CHECK-NOT: (((((
; CHECK: %tmp20 = add i32 %tmp19, %x
More information about the llvm-commits
mailing list