Instruction selection phase

Hello LLVM-Dev,

Attached are:

· The DAG after being built

· The DAG before the legalization phase

The DAG illustrated performs a signed division for type i32. As can be seen, the SDIV node was converted to a series of other nodes (which includes a MULHS node). In the target lowering class of our target, the SDIV has an operation action of custom. Does anybody know where in between the SelectionDAGBuilder and the Legalization phases the SDIV node got converted? I need the SDIV node to stay as an SDIV node until legalization phase (where it will be lowered into a library call). How can this behavior be accomplished? Does the converted series of nodes still perform the expected operation?

Thank you very much in advance for your help!

Sincerely,

Miguel Inigo J. Manalac (1852)

legalize-dags.pdf (45.5 KB)

dag-combine1.pdf (44.5 KB)

This transform is done by visitSDIV in DAGCombiner.cpp. Its using a trick to optimize division by constant. The basic idea is to replace it by a multiply by constant and a shift right with a few extra instructions needed to handle signedness correctly. Since division is usually a slow operation turning it into multiplies, shifts, adds, etc. are usually a better option. I believe you can disable this behavior by returning true in an override of TargetLowering::isIntDivCheap in your target.

Hi Craig,

Thank you very much for the help and suggestion! We were able to produce the desired behavior by setting the operation action for SMUL_LOHI and UMUL_LOHI for all integer types to expand (in target lowering class) as these nodes/instructions are not supported by our target.

Again, thank you very much for your help!!

Cheers,

Miguel