[LLVMdev] promotion of return value.

Andrew Haley aph at redhat.com
Tue Mar 31 12:41:08 PDT 2009


Rafael Espindola wrote:
>> Did you see this Ali?
>> http://nondot.org/sabre/LLVMNotes/ExtendedIntegerResults.txt
> 
> Would you mind adding it to SVN? Would make it easier
> to comment on. In particular, it would be nice to add
> examples for X86 (caller extends. High bits undefined
> in the callee) and PPC (callee extends).
> 
> And I still don't understand why in
> 
> short y();
> int z() {
>   return ((int)y() << 16) >> 16;
> }
> 
> we can remove the sign extension on x86 (I really think we cannot).

I still don't think llvm needs to do this.  We had the discussion on
http://groups.google.com/group/ia32-abi/browse_thread/thread/f47e0106b21d9269

The conclusion:

---
I think callers need to assume that return value is in %al and that
the upper bits of %eax are undefined.  If the caller needs a 32-bit
sign- or zero-extended value, it needs to do the extend itself.  I
believe GCC, ICC, and MSVC all behave this way.

Given that, it shouldn't matter how the callee handles the upper
bits.  It should do whatever is most convenient.
---

Andrew.



More information about the llvm-dev mailing list