Murali, Sriram
2013-Feb-28 18:26 UTC
[LLVMdev] Calling with register indirect reference instead of memory indirect reference.
Hi, I am working on a small optimization feature to replace the calls with indirect reference using a memory with an indirect reference using register. The purpose of this feature is to improve the performance of calls to functions referred to by function pointers. The motivation behind this work is that gcc does this optimization. Here is a small test case, that will generate an indirect call with memory reference: int main() { extern void (*foo)(); foo(); return 0; } And the corresponding assembly output is: ... main: # @main .cfi_startproc # BB#0: # %entry pushq %rax .Ltmp1: .cfi_def_cfa_offset 16 movl $2, %edi callq *foo(%rip) xorl %eax, %eax popq %rdx ret ... The patch aims to make the memory reference to use a register reference by moving the address in *foo(%rip) into a register and use it for the call. The updated assembly output is: ... main: # @main .cfi_startproc # BB#0: # %entry pushq %rax .Ltmp1: .cfi_def_cfa_offset 16 movq foo(%rip), %rax movl $0, 4(%rsp) callq *%rax xorl %eax, %eax popq %rdx ret ... However, I am unable to proceed with this fix because it modifies the SelectionDAG to insert a CopyFromReg and a CopyToReg nodes to do this operation. I tried to use a slightly modified test case, using arguments to function instead of void, and it fails. Here is the modified test case: int main() { extern void (*foo)(int); foo(2); return 0; } And the problem is that I am seeing an assertion failure with respect to the DAG structure. .file "<stdin>" llc: ~/llvm/lib/CodeGen/ScheduleDAG.cpp:510: void llvm::ScheduleDAGTopologicalSort::InitDAGTopologicalSorting(): Assertion `Node2Index[SU->NodeNum] > Node2Index[I->getSUnit()->NodeNum] && "Wrong topological sorting"' failed. 0 llc 0x000000000117ef3a llvm::sys::PrintStackTrace(_IO_FILE*) + 38 I am wondering if the modification made to the DAG is causing a problem, and can it be done at all? If I cannot do this, is there any other place I can look at, to make this work. -- Sriram Murali SSG/DPD/ECDL/DMP +1 (519) 772 - 2579 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130228/426de877/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: call_indirect_reg.patch Type: application/octet-stream Size: 3966 bytes Desc: call_indirect_reg.patch URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130228/426de877/attachment.obj>
Anton Korobeynikov
2013-Mar-01 07:56 UTC
[LLVMdev] Calling with register indirect reference instead of memory indirect reference.
Hello> I am wondering if the modification made to the DAG is causing a problem, and > can it be done at all? If I cannot do this, is there any other place I can > look at, to make this work.It's hard to tell w/o seeing the exact code / DAG. Note, however, that this assertion is seen on simple LLVM IR: http://llvm.org/bugs/show_bug.cgi?id=15053 So, it might be not your bug after all. -- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University
Murali, Sriram
2013-Mar-01 16:00 UTC
[LLVMdev] Calling with register indirect reference instead of memory indirect reference.
Hi Anton, I am attaching the Selection DAG before legalize stage (pre and post application of the patch). The test case with one int argument (fn_ptr_int_..) fails and the test case with no argument( fn_ptr_void...) doesn’t error out. I also attached the LLVM IR for the test cases if that might be of some help. Thanks Ram -----Original Message----- From: Anton Korobeynikov [mailto:anton at korobeynikov.info] Sent: Friday, March 01, 2013 2:56 AM To: Murali, Sriram Cc: llvmdev at cs.uiuc.edu Subject: Re: [LLVMdev] Calling with register indirect reference instead of memory indirect reference. Hello> I am wondering if the modification made to the DAG is causing a > problem, and can it be done at all? If I cannot do this, is there any > other place I can look at, to make this work.It's hard to tell w/o seeing the exact code / DAG. Note, however, that this assertion is seen on simple LLVM IR: http://llvm.org/bugs/show_bug.cgi?id=15053 So, it might be not your bug after all. -- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University -------------- next part -------------- A non-text attachment was scrubbed... Name: fn_ptr_int_post.png Type: image/png Size: 251146 bytes Desc: fn_ptr_int_post.png URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130301/797c4e95/attachment.png> -------------- next part -------------- A non-text attachment was scrubbed... Name: fn_ptr_int_pre.png Type: image/png Size: 222527 bytes Desc: fn_ptr_int_pre.png URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130301/797c4e95/attachment-0001.png> -------------- next part -------------- A non-text attachment was scrubbed... Name: fn_ptr_void_post.png Type: image/png Size: 205647 bytes Desc: fn_ptr_void_post.png URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130301/797c4e95/attachment-0002.png> -------------- next part -------------- A non-text attachment was scrubbed... Name: fn_ptr_void_pre.png Type: image/png Size: 175714 bytes Desc: fn_ptr_void_pre.png URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130301/797c4e95/attachment-0003.png> -------------- next part -------------- A non-text attachment was scrubbed... Name: fn_ptr_int_post.ll Type: application/octet-stream Size: 846 bytes Desc: fn_ptr_int_post.ll URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130301/797c4e95/attachment.obj> -------------- next part -------------- A non-text attachment was scrubbed... Name: fn_ptr_void_post.ll Type: application/octet-stream Size: 835 bytes Desc: fn_ptr_void_post.ll URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130301/797c4e95/attachment-0001.obj>
Maybe Matching Threads
- [LLVMdev] Calling with register indirect reference instead of memory indirect reference.
- [PATCH] x86: fix emulation of indirect far calls and jumps
- total indirect effects in structural equation modeling using lavaan
- Direct and Indirect: Difference in rendering quality
- [PATCH 2/3] virtio: indirect ring entries (VIRTIO_RING_F_INDIRECT_DESC)