Calling with register indirect reference instead of memory indirect reference.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Calling with register indirect reference instead of memory indirect reference.

Murali, Sriram

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

 


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

call_indirect_reg.patch (5K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Calling with register indirect reference instead of memory indirect reference.

Anton Korobeynikov-2
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
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: Calling with register indirect reference instead of memory indirect reference.

Murali, Sriram
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:[hidden email]]
Sent: Friday, March 01, 2013 2:56 AM
To: Murali, Sriram
Cc: [hidden email]
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

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

fn_ptr_int_post.png (335K) Download Attachment
fn_ptr_int_pre.png (297K) Download Attachment
fn_ptr_void_post.png (274K) Download Attachment
fn_ptr_void_pre.png (234K) Download Attachment
fn_ptr_int_post.ll (1K) Download Attachment
fn_ptr_void_post.ll (1K) Download Attachment