[PATCH] D34025: [SCEV] Teach SCEVExpander to expand BinPow
Daniel Neilson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 8 07:35:36 PDT 2017
dneilson added a comment.
Have you looked at what happens with addition? i.e.
x = a;
for (i = 0; i < N; i++) x = x + x;
Should still be an exponential number of additions, when it could be just (x * (N << 1)).
================
Comment at: lib/Analysis/ScalarEvolutionExpander.cpp:766
+ // 1u << 31 at most to not deal with unsigned overflow.
+ while (E != OpsAndLoops.end() && *I == *E && Exponent != MaxExponent) {
+ ++Exponent; ++E;
----------------
How challenging would it be to enhance SCEVMulExpr to represent repeated multiplies by the same value as a pair (value, exponent) rather than as a list of the same value being repeated 'exponent' times?
This patch has addressed not having to expand a ^ (2 ^ N) at runtime, but we still have an exponential number of terms in the OpsAndLoops list, which should quite negatively affect compile time.
================
Comment at: lib/Analysis/ScalarEvolutionExpander.cpp:773
+ // that are needed into the result.
+ Value *P = expandCodeFor(I->second, Ty);
+ Value *Result = nullptr;
----------------
If Ty is a float type and N isn't a trivial value (like 1 or 2) then it can be better (faster & more accurate) to generate a call to @llvm.powi rather than the tree of multiplies.
https://reviews.llvm.org/D34025
More information about the llvm-commits
mailing list