[LLVMdev] promotion of return value.

Duncan Sands
Sat, 14 Mar 2009 10:18:54 -0000

Hi,

> What we are trying to do is to add new attributes (more maybe added
> later):
>
> >   sign_ext_from_i8, sign_ext_from_i16
> >   zero_ext_from_i8, zero_ext_from_i16
>
> to function definition so (assuming that both caller and callee are
> generated in the same front-end) the caller will know if the callee has
> already extended the return value or not, then it can promote only if
> needed.

I don't understand what the point of this is.  Surely this can all be
handled by the calling convention and the signext/zeroext attributes?
For example, suppose a function returns a short, but on the target that
means being returned in an i32, with sign extension.  Then in the IR the
function is defined as returning an i16 with the signext attribute:

  define signext i16 @f(...

The target calling convention specifies that i16's are returned in
i32's.  When code is generated for @f this means that you get something
like:

      0x2696eb8: i16,ch = ...                         <= the i16 value
    0x2696fb0: i32 = sign_extend 0x2696eb8            <= sign extended to i32
    0x26970a8: ch = ArgFlags < >
  0x26971a0: ch = ret 0x2696ad8, 0x2696fb0, 0x26970a8 <= here returned

Perfect!

Ciao,

Duncan.