Integer promotion of return node operand

Hi All,

Please consider the following case

Test case --

When LLVM constructs the DAG for above case - it tries to promote
(during DAG construction phase - before any combine or legalize phase)
the return node operand to i32.

I have few doubts here:
1) If C language requires integer promotion of return value argument
then should it not be done by the C language frontend. (I think LLVM is
langauge
independent). This is what happens when we use char in calculations.
Clang promotes char in calculations to int and this promotion is visible
in the disassembly. However return node operand promotion is not visible
in disassembly but LLVM is doing that.

I think all currently defined calling conventions are "C like". You can add a calling convention and check for it in visitRet.

2) Also should the char not be promoted to target integer (Target
integer may be 16 bits). LLVM tries to promote to i32 (promotion to i32
is hardcoded in file SelectionDAGISel.cpp - function visitRet).

  The comment in LLVM code says "C calling convention requires
the return type to be promoted to atleast 32 bits. But this is not
necessary for non-C calling conventions." What about targets where
integer size is not 32 bits ??

I think C calling convention requires promotion to "int" type. So if your int is 16-bit, it should be promoted to 16-bits. Someone else would chime in, I am not 100% about this.

3) And How should this promotion be handled when the target does not
have register to handle int size. e.g. if a target has int size of 16
bits but the register size of 8 bits.

I am not sure how that would work. I'd think you need to have int register class. How does your target handle i16? Can it use register pair?

Evan

Hi,

> 1) If C language requires integer promotion of return value argument
> then should it not be done by the C language frontend. (I think LLVM
> is
> langauge
> independent). This is what happens when we use char in calculations.
> Clang promotes char in calculations to int and this promotion is
> visible
> in the disassembly. However return node operand promotion is not
> visible
> in disassembly but LLVM is doing that.

I think all currently defined calling conventions are "C like". You
can add a calling convention and check for it in visitRet.

I agree with the OP that this kind of promotion should be done by the
language front-end.

> 3) And How should this promotion be handled when the target does not
> have register to handle int size. e.g. if a target has int size of 16
> bits but the register size of 8 bits.

I am not sure how that would work. I'd think you need to have int
register class. How does your target handle i16? Can it use register
pair?

Presumably this is the same as using i64 on an i32 machine.

Ciao,

Duncan.