Roland Scheidegger
2010-Oct-20 01:37 UTC
[LLVMdev] llvm register reload/spilling around calls
Thanks for giving it a look! On 19.10.2010 23:21, Jakob Stoklund Olesen wrote:> On Oct 19, 2010, at 11:40 AM, Roland Scheidegger wrote: > >> So I saw that the code is doing lots of register >> spilling/reloading. Now I understand that due to calling >> conventions, there's not really a way to avoid this - I tried using >> coldcc but apparently the backend doesn't implement it and hence >> this is ignored. > > Yes, unfortunately the list of call-clobbered registers is fixed at > the moment, so coldcc is mostly ignored by the backend. > > Patches welcome.What would be needed there? I actually tried a quick hack and simply changed the registers included in the list in X86RegisterInfo::getCalleeSavedRegs, so some xmm regs were included (similar to what was done for win64). But the result wasn't what I expected - the callee now indeed saved/restored all the xmm regs I added, however the calling code did not change at all...> >> So is there any optimization option I'm missing which could improve >> this? Or is this simply the way things are (would that be >> considered a bug?). If this is a known limitation, any ideas if >> it's possible to work around that (by changing the affected jit >> code)? > > The -pre-alloc-split option should handle stuff like this when calls > clobber an entire register class. That probably only applies to XMM > registers.I tried that and the generated code did not change at all.> > Work on proper live range splitting is in progress. You can try it > out with -spiller=inline, but it is highly experimental and volatile > at the moment.Tried that too but the code mostly remained the same (there were 2 additional spills right at the beginning and some of the register numbers changed but that was all). There's also a -spiller=splitting option, I don't know what it should do but it just crashed... Roland> > I don't know any short term solutions. > > /jakob >
Jakob Stoklund Olesen
2010-Oct-20 03:00 UTC
[LLVMdev] llvm register reload/spilling around calls
On Oct 19, 2010, at 6:37 PM, Roland Scheidegger wrote:> Thanks for giving it a look! > > On 19.10.2010 23:21, Jakob Stoklund Olesen wrote: >> On Oct 19, 2010, at 11:40 AM, Roland Scheidegger wrote: >> >>> So I saw that the code is doing lots of register >>> spilling/reloading. Now I understand that due to calling >>> conventions, there's not really a way to avoid this - I tried using >>> coldcc but apparently the backend doesn't implement it and hence >>> this is ignored. >> >> Yes, unfortunately the list of call-clobbered registers is fixed at >> the moment, so coldcc is mostly ignored by the backend. >> >> Patches welcome. > What would be needed there? I actually tried a quick hack and simply > changed the registers included in the list in > X86RegisterInfo::getCalleeSavedRegs, so some xmm regs were included > (similar to what was done for win64). But the result wasn't what I > expected - the callee now indeed saved/restored all the xmm regs I > added, however the calling code did not change at all...Look in X86InstrControl.td. The call instructions are all prefixed by: let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11, FP0, FP1, FP2, FP3, FP4, FP5, FP6, ST0, ST1, MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7, XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7, XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS], This is the fixed list of call-clobbered registers. It should really be controlled by the calling convention of the called function instead. The WINCALL* instructions only exist because of this. One problem is that calling conventions are handled while building the selection DAG, and the DAG doesn't really know to represent clobbered registers. Perhaps X86TargetLowering::LowerCall() could decorate the X86ISD::CALL node with the calling convention somehow? Dan, do you have any thoughts on how to communicate the calling convention and call clobbered registers to the eventual CALL MachineInstr? /jakob -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 1929 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20101019/6ab1ee89/attachment.bin>
Roland Scheidegger
2010-Oct-20 14:46 UTC
[LLVMdev] llvm register reload/spilling around calls
On 20.10.2010 05:00, Jakob Stoklund Olesen wrote:> On Oct 19, 2010, at 6:37 PM, Roland Scheidegger wrote: > >> Thanks for giving it a look! >> >> On 19.10.2010 23:21, Jakob Stoklund Olesen wrote: >>> On Oct 19, 2010, at 11:40 AM, Roland Scheidegger wrote: >>> >>>> So I saw that the code is doing lots of register >>>> spilling/reloading. Now I understand that due to calling >>>> conventions, there's not really a way to avoid this - I tried >>>> using coldcc but apparently the backend doesn't implement it >>>> and hence this is ignored. >>> Yes, unfortunately the list of call-clobbered registers is fixed >>> at the moment, so coldcc is mostly ignored by the backend. >>> >>> Patches welcome. >> What would be needed there? I actually tried a quick hack and >> simply changed the registers included in the list in >> X86RegisterInfo::getCalleeSavedRegs, so some xmm regs were included >> (similar to what was done for win64). But the result wasn't what I >> expected - the callee now indeed saved/restored all the xmm regs I >> added, however the calling code did not change at all... > > Look in X86InstrControl.td. The call instructions are all prefixed > by: > > let Defs = [RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11, FP0, FP1, FP2, > FP3, FP4, FP5, FP6, ST0, ST1, MM0, MM1, MM2, MM3, MM4, MM5, MM6, MM7, > XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7, XMM8, XMM9, XMM10, > XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS], > > This is the fixed list of call-clobbered registers. It should really > be controlled by the calling convention of the called function > instead. > > The WINCALL* instructions only exist because of this.Ahh I see now. I hacked this up and indeed the code looks much better. I can't force it to use win64 calling conventions right? Would do just fine for this case (much closer to a cold calling convention, I really only need 5 preserved xmm regs). Roland> > One problem is that calling conventions are handled while building > the selection DAG, and the DAG doesn't really know to represent > clobbered registers. > > Perhaps X86TargetLowering::LowerCall() could decorate the > X86ISD::CALL node with the calling convention somehow? > > Dan, do you have any thoughts on how to communicate the calling > convention and call clobbered registers to the eventual CALL > MachineInstr? > > /jakob >
On Oct 19, 2010, at 8:00 PM, Jakob Stoklund Olesen wrote:> > > One problem is that calling conventions are handled while building the selection DAG, and the DAG doesn't really know to represent clobbered registers. > > Perhaps X86TargetLowering::LowerCall() could decorate the X86ISD::CALL node with the calling convention somehow? > > Dan, do you have any thoughts on how to communicate the calling convention and call clobbered registers to the eventual CALL MachineInstr?The simplest way would probably be to add separate X86ISD opcodes for each desired set of call-clobbered registers. Dan
Reasonably Related Threads
- [LLVMdev] llvm register reload/spilling around calls
- [LLVMdev] llvm register reload/spilling around calls
- [LLVMdev] llvm register reload/spilling around calls
- [LLVMdev] llvm register reload/spilling around calls
- [LLVMdev] Codegen/Register allocation question.