[llvm-commits] [llvm] r132316 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineMulDivRem.cpp test/Transforms/InstCombine/2011-05-28-swapmulsub.ll

Frits van Bommel fvbommel at gmail.com
Mon May 30 14:52:55 PDT 2011


On Mon, May 30, 2011 at 10:19 PM, Duncan Sands <baldrick at free.fr> wrote:
>> +    // The "* 2" thus becomes a potential shifting opportunity.
>> +    {
>> +      const APInt&    Val = CI->getValue();
>> +      const APInt&PosVal = Val.abs();
>> +      if (Val.isNegative()&&  PosVal.isPowerOf2()) {
>
> You should also check that Op0, aka (1-X), has only one use.  Also, why does it
> matter that it is "1-X" specifically?  Surely "Constant - X", "X - Constant",
> "Constant+X" and "X-Constant" are also fine, since you don't increase the
> amount of computation in any of these when you push the "*(-1)" into them?

You mentioned "X-Constant" twice, but you probably meant "X+Constant"
the second time.

There's no need to match "Constant+X", since it will be turned into
"X+Constant" by other parts of instcombine.

I also don't think that for the subtraction case you even need either
one to be a constant at all. -(X-Y) == (Y-X) even for non-constant X
and Y.

That leaves just the cases "(X-Y)*-PowerOfTwo" and
"(X+Constant)*-PowerOfTwo" to consider.




More information about the llvm-commits mailing list