[LLVMdev] promotion of return value.

Rafael Espindola
Fri, 13 Mar 2009 19:55:15 -0000

2009/3/13  <Alireza.Moshtaghi at microchip.com>:
> Some targets want to do the promotion in the callee and some in the
> caller. Now what you are discussing in your bug is we shouldn't do in
> both...

exactly.

> Now the tricky part is that many targets (not for the sake of promotion,
> but for the sake of performance) return a smaller value in a larger
> register (say if the function is to return char, they return it in 32
> bit register);
> So they are effectively promoting the return value on the callee side,
> then the caller takes the part that it needs and again promotes it to
> comply with the rules of integer promotion stuff, hence double
> promotion.
>
> 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.
>
> You may argue that this all can be done per a target-defined convention
> and I think that is the theory behind the patches that are used to fix
> your bug.
> However, we had this discussion last year, and it was decided to make
> things more transparent by adding the aforementioned attributes. Please
> look at the thread:

My proposal is to make the extension as explicit as possible. If the
callee is extending an char to an int, the generated llvm code should
return an i32 and the caller can assume that the extension has been done.

Are you saying that the decision to do the extension in the callee happens
after we have generated llvm? That is, an optimization is transforming
a function that would return an i8 into one that returns i16 or i32?

Do you have a testcase for the problem you are trying to solve?

> http://www.nabble.com/Troubling-promotion-of-return-value-to-Integer-...
> -to17237327.html#a17237327

I am sorry I missed the thread. I will take a look.

> Regards,
> Ali

Cheers,
--
Rafael Avila de Espindola

Google | Gordon House | Barrow Street | Dublin 4 | Ireland
Registered in Dublin, Ireland | Registration Number: 368047