[LLVMdev] Multiply i8 operands promotes to i32

Eli Friedman eli.friedman at gmail.com
Mon Oct 8 04:08:55 PDT 2012

On Mon, Oct 8, 2012 at 2:44 AM, Pedro Malagón <malagon at die.upm.es> wrote:
> Hi,
> I am trying to complete the hardware multiplier option for MSP430 backend.
> As the hardware multiplier in most of the MSP430 devices is for i8 and
> i16 operands, with i16 and i32 result, I am lowering MUL_i8 and MUL_I16.
> However, the front-end promotes the i8 argument to i32, executes 32-bit
> multiplier and truncates to 16-bit, so I never lower MUL_I8 nor MUL_I16
> but MUL_I32, wchich is lowered to an external libcall (__mulsi3) that I
> don´t have.
> What should I do in order to prevent the front-end from promote to
> 32-bit multiplier?

(I'm assuming you're getting C code from clang.)

You can't, assuming your platform defines "int" to be 32 bits; clang
is just following the C standard.  This may seem a little silly in
this case, but clang generally tries to generate math operations as

> If that is not possible, how can I detect when lowering that it is
> actually a MUL_I8 or MUL_I16 in order to do the correct lowering?

At -O0, you don't.  __mulsi3 is the obvious lowering, and you're doing
something wrong if your tools don't provide it.

There are probably some interesting issues with the current optimizers
at -O2, but it's hard to discuss that without specific examples.


More information about the llvm-dev mailing list