[LLVMdev] 32bit math being promoted to 64 bit
Eli Friedman
eli.friedman at gmail.com
Thu Dec 4 13:23:53 PST 2008
On Thu, Dec 4, 2008 at 10:43 AM, Villmow, Micah <Micah.Villmow at amd.com> wrote:
> instcombine doesn't seem to be doing it. From my testing it seems to
> only occur when I use -indvars after a long string of commands.
Yes, it's indvars. And at least on an architecture with a reasonably
efficient 64-bit multiply, we want to do this. The rewritten version
manages to eliminate the loop completely: it's rewriting the
loop-carried value as a direct computation, and this is generally a
good thing. The code that computes the formula is BinomialCoefficient
in ScalarEvolution.cpp, and the code that puts it into the code is
IndVarSimplify::RewriteLoopExitValues.
That said, this could be really bad on an architecture which can't
perform this kind of multiply natively. Currently, the code has a
hack to disallow generating SCEVs with multiplies larger than 64 bits.
There's a few issues here: one, the code is in the wrong place. And
two, we don't really know the characteristics of the target when we're
running indvars.
For this particular case (a quadratic addrec), though, it's actually
possible to rewrite it without the 64-bit multiply: an equivalent
expression for %tmp.17 is "((%tmp6-1)/2)*((%tmp6-2)|1)". Until we
have a better solution, it might be reasonable to teach the SCEV
expander to recognize this alternate expression for the operation in
question, and make indvars refuse to expand wider addrecs (which tend
to be quite rare).
-Eli
More information about the llvm-dev
mailing list