<div dir="ltr"><div><div><div><div><div>Dear All,<br><br></div>I am new to Haskell so please forgive me if I am asking about something already well-understood.<br><br>I was trying to understand the performance of my Haskell program compiled with the LLVM backend. I used -ddump-llvm to dump the LLVM assembly and then ran llc -O3 on the resulting file to look at the native assembly.<br>

<br></div>One of the generated function starts off with<br>s5BH_info:                              # @s5BH_info<br># BB#0:   <br>        subq    $208, %rsp<br>        movq    %r13, 200(%rsp)<br>        movq    %rbp, 192(%rsp)<br>

        movq    %r12, 184(%rsp)<br>        movq    %rbx, 176(%rsp)<br>        movq    %r14, 168(%rsp)<br>        movq    %rsi, 160(%rsp)<br>        movq    %rdi, 152(%rsp)<br>        movq    %r8, 144(%rsp)<br>        movq    %r9, 136(%rsp)<br>

        movq    %r15, 128(%rsp)<br>        movss   %xmm1, 124(%rsp)<br>        movss   %xmm2, 120(%rsp)<br>        movss   %xmm3, 116(%rsp)<br>        movss   %xmm4, 112(%rsp)<br>        movsd   %xmm5, 104(%rsp)<br>        movsd   %xmm6, 96(%rsp)<br>

<br></div>At some point down the line the function makes a tail call to itself and this is the code generated<br>        movq    %r14, 168(%rsp)<br>        movq    200(%rsp), %r13<br>        movq    192(%rsp), %rbp<br>        movq    184(%rsp), %r12<br>

        movq    176(%rsp), %rbx<br>        movq    128(%rsp), %r15<br>        movsd   104(%rsp), %xmm5<br>        addq    $208, %rsp<br>        jmp     s5BH_info <br><br></div>So it looks like some values are being moved from registers to the stack only to be immediately moved from the stack to the register on entry to the function. It should be possible to eliminate both the load and the stores.<br>

<br>Is this behaviour due to LLVM or GHC? If it is GHC, it this an optimization a newcomer can attempt to implement or are there deep issues here?<br><br></div><div>Jyotirmoy Bhattacharya<br></div><div><div><br><div><br>
</div>
</div></div></div>