#7308: Better code for top-level indirections ---------------------------------+------------------------------------------ Reporter: simonpj | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.1 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: None/Unknown Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ GHC generates lots of top-level indirections looking like this: {{{ foo :: T foo = bar `cast` (some coercion) }}} There are good reasons for this. Moreover `foo` will almost never be evaluated, because GHC will inline any call to `foo` at its call site.
'''But''' GHC generates rather a lot of code for this one (almost-vacuous) bindings: {{{ .align 4,0x90 .long _Swx_srt-(_Foo_zdfTypeableT_info)+4 .long 0 .long 65558 .globl _Foo_zdfTypeableT_info _Foo_zdfTypeableT_info: .LcwI: movl %esi,%eax leal -8(%ebp),%ecx cmpl 84(%ebx),%ecx jb .LcwP addl $8,%edi cmpl 92(%ebx),%edi ja .LcwR movl $_stg_CAF_BLACKHOLE_info,-4(%edi) movl 100(%ebx),%ecx movl %ecx,0(%edi) leal -4(%edi),%ecx pushl %ecx pushl %eax pushl %ebx movl %eax,76(%esp) call _newCAF addl $12,%esp testl %eax,%eax je .LcwK movl $_stg_bh_upd_frame_info,-8(%ebp) leal -4(%edi),%eax movl %eax,-4(%ebp) movl $_Foo_zdfTypeableTzuzdctypeOf_closure+1,%esi addl $-8,%ebp jmp *(%ebp) .LcwK: movl 64(%esp),%eax jmp *(%eax) .LcwR: movl $8,116(%ebx) .LcwP: movl %eax,%esi jmp *-12(%ebx) }}} Whereas all we really need for `foo` is code that says "jump to `bar`". No need to update that top-level thunk. It's just an indirection and (if you have `-O` on) one that will never even be used. In short, I think that top-level indirections could do with a tiny special case in the code generator. -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7308> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler _______________________________________________ Glasgow-haskell-bugs mailing list Glasgow-haskell-bugs@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs