[Haskell-cafe] redundant loads and saves in code generated for recursive functions?
10 views
Skip to first unread message
Jyotirmoy Bhattacharya
unread,
Jul 30, 2014, 4:25:29 AM7/30/14
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to haskel...@haskell.org
Dear All,
I am new to Haskell so please forgive me if I am asking about something already well-understood.
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.
At some point down the line the function makes a tail call to itself and this is the code generated movq %r14, 168(%rsp) movq 200(%rsp), %r13 movq 192(%rsp), %rbp movq 184(%rsp), %r12
movq 176(%rsp), %rbx movq 128(%rsp), %r15 movsd 104(%rsp), %xmm5 addq $208, %rsp jmp s5BH_info
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.
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?
Jyotirmoy Bhattacharya
Jyotirmoy Bhattacharya
unread,
Jul 30, 2014, 6:04:46 AM7/30/14
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to haskel...@haskell.org
On reading this again I realise that I got the order of loads and stores wrong. The arguments are being stored on entering the function and loaded before the call. But still, is there a chance of eliminating this redundancy?
Jyotirmoy
Johan Tibell
unread,
Jul 30, 2014, 6:45:05 AM7/30/14
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Johan Tibell, haskell-cafe
Hi,
It doesn't seem the same to me.
Unlike the bug you point to, the C-- does not have any extra stores. The stores and loads appear first in the LLVM. I am attaching the C--, LLVM and assembly codes for the function.
The real missed opportunity seems to me the absence of a recognition that we are in fact making a tail call to ourselves. Recognizing that might allow jumping to some point after the initial stores.
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Jyotirmoy Bhattacharya, haskell-cafe
I see. I think this is worthwhile to file a bug for. Please include
the cmm, asm, and llvm as attachedment (and perhaps a short Haskell
program that show the issue).
On Wed, Jul 30, 2014 at 2:10 PM, Jyotirmoy Bhattacharya
Jyotirmoy Bhattacharya
unread,
Jul 30, 2014, 1:38:05 PM7/30/14
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message