Sachin.Punyani at microchip.com
2008-May-12 15:21 UTC
[LLVMdev] Integer promotion of return node operand
Hi All, Please consider the following case Test case -- -------------------------------------- char a; void fun () { return a; } -------------------------------------- Following disassembly (using llvm-dis) is generated for the above test case -------------------------------------- ; ModuleID = 'first.bc' @a = internal global i8 0 ; <i8*> [#uses=1] define i8 @fun(...) { entry: %tmp = load i8* @a ; <i8> [#uses=1] ret i8 %tmp } -------------------------------------- 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. 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 ?? 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. Regards -:SP:-
On May 12, 2008, at 8:21 AM, Sachin.Punyani at microchip.com wrote:> > 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> > > > Regards > -:SP:- > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
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.
Possibly Parallel Threads
- [LLVMdev] Integer promotion of return node operand
- [LLVMdev] FW: Integer promotion of return node operand
- [LLVMdev] Troubling promotion of return value to Integer ...
- [LLVMdev] Troubling promotion of return value to Integer ...
- [LLVMdev] trouble with 32-bit promotion of return value