[PATCH] D34025: [SCEV] Teach SCEVExpander to expand BinPow
Max Kazantsev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 8 02:46:56 PDT 2017
mkazantsev created this revision.
Herald added a subscriber: mzolotukhin.
SCEV tends to keep its expressions as flat as possible, preferring (a * b * c * d) over ((a * b) * (c * d)).
As result, if we have something like
x = a;
for (i = 0; i < N; i++) x = x * x;
which actually calculates a ^ (2 ^ N), its SCEV will look like (a * a * a * ... * a), the amount of
operands is 2 ^ N. If we try to expand such an expression, we will naively produce approx. 2 ^ N
mul instructions. To avoid this situation, this patch teaches SCEV Expander to deal with such
expressions generating a Binary Pow instruction sequence:
Let N be https://reviews.llvm.org/P1 + https://reviews.llvm.org/P2 + ... + PK, where all P are powers of 2. Then a ^ (2 ^ N) = (a ^ https://reviews.llvm.org/P1) * (a ^ https://reviews.llvm.org/P2) * ... * (a ^ PK),
so the number of instructions becomes O(log(N)).
https://reviews.llvm.org/D34025
Files:
lib/Analysis/ScalarEvolutionExpander.cpp
test/Transforms/LoopStrengthReduce/X86/big_power.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34025.101874.patch
Type: text/x-patch
Size: 9023 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170608/1f0340d3/attachment.bin>
More information about the llvm-commits
mailing list