[llvm-commits] [llvm] r103881 - in /llvm/trunk: lib/Target/ARM/ARMISelLowering.cpp test/CodeGen/ARM/mul_const.ll

Jakob Stoklund Olesen stoklund at 2pi.dk
Sun May 16 10:32:16 PDT 2010


On May 16, 2010, at 1:30 AM, Evan Cheng wrote:

> 
> On May 15, 2010, at 9:14 PM, Jakob Stoklund Olesen wrote:
>> Translating (mul x, 2^N) -> (shl x, n) in the dag combiner sounds reasonable, and we are already doing that in DAGCombiner::visitMUL.
>> 
>> Then there is (mul x, 2^N+1) -> (add (shl x, n), x) and (mul x, 2^N-1) -> (sub (shl x, n), x). For these, X86 prefers to use LEA for factors 3, 5, and 9, so we are probably better off leaving that target dependent.
> 
> I would have preferred if dag combine does the transformation and x86 isel matches to the LEA. If it doesn't just work, then it's not a huge deal.

The transformation is in the function PerformMulCombine() in X86ISelLowering.cpp. It inserts an X86ISD::MUL_IMM node, presumably to prevent further DAG combinations on it. That X86ISD::MUL_IMM is then matched to LEA or folded into an address operand.

It tries to put the MUL_IMM last such that (mul x, 48) becomes (MUL_IMM 3, (shl x, 4)). This makes it easier to match to an addressing mode.

This could be done with a target independent transform:

 (mul x, 48) -> (add y, (shl y, 1)), y = (shl x, 4).

or

 (mul x, 48) -> (shl (add x, (shl x, 1)), 4).

But it is not clear that this transform would be a benefit to all targets, and the first one is better than the second for X86 because it partially matches an addressing mode.

There are many ways of expanding constant multiplication, and which is best is target dependent.






More information about the llvm-commits mailing list