[GHC] #8083: setNumCapabilities broken in HEAD

GHC ghc-devs at haskell.org
Tue Jul 23 14:55:49 CEST 2013


#8083: setNumCapabilities broken in HEAD
------------------------------------------------+--------------------------
        Reporter:  parcs                        |            Owner:
            Type:  bug                          |           Status:  new
        Priority:  normal                       |        Milestone:
       Component:  Runtime System               |          Version:  7.7
      Resolution:                               |         Keywords:
Operating System:  Unknown/Multiple             |     Architecture:
 Type of failure:  Incorrect result at runtime  |  Unknown/Multiple
       Test Case:  T8083                        |       Difficulty:
        Blocking:                               |  Unknown
                                                |       Blocked By:
                                                |  Related Tickets:
------------------------------------------------+--------------------------
Changes (by igloo):

 * testcase:   => T8083


Comment:

 We get this:
 {{{
 ==================== Post control-flow optimisations ====================
 {offset
   c18y:
       if (Sp - <highSp> < SpLim) goto c18D; else goto c18E;
   c18D:
       R1 = Main.main1_closure;
       call (stg_gc_fun)(R1) args: 8, res: 0, upd: 8;
   c18E:
       _s188::I64 = %MO_SS_Conv_W32_W64(I32[n]);
       _s188::I64 = _s188::I64;
       _s189::I64 = _s188::I64;
       if (_s189::I64 != 1) goto c18w; else goto c18x;
   c18w:
       R1 = GHC.Tuple.()_closure+1;
       call (P64[(old + 8)])(R1) args: 8, res: 0, upd: 8;
   c18x:
       _c18B::I64 = blah;
       I64[(young<c18C> + 8)] = c18C;
       foreign call "ccall" arg hints:  []  result hints:  []
 (_c18B::I64)(...) returns to c18C args: ([]) ress: ([])upd: 8;
   c18C:
       R1 = GHC.Tuple.()_closure+1;
       call (P64[(old + 8)])(R1) args: 8, res: 0, upd: 8;
 }
 }}}
 note that `c18w` and `c18C` look identical. They then get commoned up:
 {{{
 ==================== Post common block elimination ====================
 {offset
   c18y:
       if (Sp - <highSp> < SpLim) goto c18D; else goto c18E;
   c18D:
       R1 = Main.main1_closure;
       call (stg_gc_fun)(R1) args: 8, res: 0, upd: 8;
   c18E:
       _s188::I64 = %MO_SS_Conv_W32_W64(I32[n]);
       _s188::I64 = _s188::I64;
       _s189::I64 = _s188::I64;
       if (_s189::I64 != 1) goto c18w; else goto c18x;
   c18x:
       _c18B::I64 = blah;
       I64[(young<c18w> + 8)] = c18w;
       foreign call "ccall" arg hints:  []  result hints:  []
 (_c18B::I64)(...) returns to c18w args: ([]) ress: ([])upd: 8;
   c18w:
       R1 = GHC.Tuple.()_closure+1;
       call (P64[(old + 8)])(R1) args: 8, res: 0, upd: 8;
 }
 }}}
 The problem is that the code ends up looking like this:
 {{{
 # at this point rbp = <stg_catch_frame_info>
 _c18E:
     movslq n,%rax
     cmpq $1,%rax
     jne _c18w
 # if n /= 1, we jump to _c18w with rbp = <stg_catch_frame_info>, and _c18w
 will jump to stg_catch_frame_info.
 _c18x:
     movq $block_c18w_info,-8(%rbp)
     addq $-8,%rbp
 # Now we've pushed _c18w onto the stack
     movq 296(%r13),%rax
     movq 24(%rax),%rax
 # save the stack...
     movq %rbp,16(%rax)
     leaq 8(%r12),%rax
     movq 312(%r13),%rbx
     movq %rax,8(%rbx)
     movq %r13,%rdi
     xorl %esi,%esi
     subq $8,%rsp
     movl $0,%eax
     call suspendThread
     addq $8,%rsp
     subq $8,%rsp
     movq %rax,%rbx
     movl $0,%eax
     call blah
     addq $8,%rsp
     movq %rbx,%rdi
     subq $8,%rsp
     movl $0,%eax
     call resumeThread
     addq $8,%rsp
     movq %rax,%r13
     movq 296(%r13),%rax
     movq 24(%rax),%rax
 # ...restore the stack
     movq 16(%rax),%rbp
     leaq 192(%rax),%r15
     movq $0,328(%r13)
     movq 312(%r13),%rax
     movq 8(%rax),%rax
     leaq -8(%rax),%r12
     movq 312(%r13),%rax
     movslq 48(%rax),%rax
     shlq $12,%rax
     decq %rax
     movq 312(%r13),%rbx
     movq (%rbx),%rbx
     addq %rax,%rbx
     movq %rbx,280(%r13)
 # jump to the top fo the stack - that's the _c18w that we pushed earlier.
 # But now _c18w will jump to the top of the stack - which is still _c18w!
 # Infinite loop.
     jmp *(%rbp)
 block_c18w_info:
 _c18w:
     movl $GHC.Tuple.()_closure+1,%ebx
     jmp *(%rbp)
 }}}

 The second jump to `_c18w` wanted to be jumping to somewhere that would
 also add 8 to the stack pointer.

 For now I've disabled the common block eliminator in `cmm/CmmPipeline.hs`,
 which gets everything working, but we should fix this better.

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8083#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler




More information about the ghc-tickets mailing list