Opened 3 years ago

Closed 3 years ago

#7498 closed bug (fixed)

panic : Register allocator: out of stack slots (need 147)

Reported by: erikd Owned by:
Priority: high Milestone: 7.8.1
Component: Compiler Version: 7.7
Keywords: Cc: pho@…
Operating System: Unknown/Multiple Architecture: powerpc
Type of failure: Building GHC failed Test Case:
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description

Build current GHC HEAD on linux-powerpc.

Usign the stage1 to build compiler/main/DynFlags.hs -o compiler/stage2/build/DynFlags.o I get:

ghc-stage1: panic! (the 'impossible' happened)
  (GHC version 7.7.20121212 for powerpc-unknown-linux):
        Register allocator: out of stack slots (need 147)
   If you are trying to compile SHA1.hs from the crypto library then this
   is a known limitation in the linear allocator.

   Try enabling the graph colouring allocator with -fregs-graph instead.
   You can still file a bug report if you like.

Change History (13)

comment:1 Changed 3 years ago by simonmar

  • difficulty set to Unknown
  • Milestone set to 7.8.1
  • Priority changed from normal to high

Someone needs to implement this: 0b0a41f96cbdaf52aac171c9c58459e3187b0f46 for PowerPC. It's not hard, just crib from the x86 example.

comment:2 Changed 3 years ago by erikd

  • Owner set to erikd

comment:3 Changed 3 years ago by erikd@…

commit 51d364530895e2f18fa8b98a12bf5a44f1b004d1

Author: Erik de Castro Lopo <[email protected]>
Date:   Sun Dec 16 04:40:54 2012 +1100

    PPC: Implement stack resizing for the linear register allocator.
    
    Fixes #7498.

 compiler/nativeGen/AsmCodeGen.lhs |    2 +-
 compiler/nativeGen/PPC/Instr.hs   |   72 +++++++++++++++++++++++++++++-------
 2 files changed, 59 insertions(+), 15 deletions(-)

comment:4 Changed 3 years ago by simonmar

  • Resolution set to fixed
  • Status changed from new to closed

@erikd: I think I've now given you permission to close tickets on Trac.

comment:5 Changed 3 years ago by PHO

  • Cc pho@… added

comment:6 Changed 3 years ago by PHO

  • Operating System changed from Linux to Unknown/Multiple
  • Owner erikd deleted
  • Resolution fixed deleted
  • Status changed from closed to new

In HEAD the stage-2 compiler segfaults at StgReturn because of the stack pointer r1 pointing to an invalid address during the compilation of libraries/old-time/dist-install/build/System/Time.p_o. I found PPC.Instr.insertBeforeNonlocalTransfers (possibly mistakenly) inserts dealloc before every jumpish instruction including local jumps so I modified it as follows, but my fix didn't work:

insertBeforeNonlocalTransfers :: Instr -> [Instr] -> [Instr]
insertBeforeNonlocalTransfers insert insns
    = foldr p [] insns
    where
      -- BCTR might or might not be a non-local jump. For
      -- "labeled-goto" we use JMP, and for "computed-goto" we use
      -- MTCTR followed by BCTR. See 'PPC.CodeGen.genJump'.
      p insn r = case insn of
                   JMP  _          -> insert : insn : r
                   BCTR [] Nothing -> insert : insn : r
                   _               ->          insn : r
      -- BL and BCTRL are call-like instructions rather than jumps,
      -- and are used only for C calls.

The real cause is not in the PPC specific code, but in the current algorithm (shared with X86) for allocMoreStack collapsing at local branches or fall-through to join points. Suppose we have two blocks L0 and L1, where L0 is the proc entry point and L1 is a join point:

L0:
    ...
    if (...) { call something() returning to L1; }
L1:
    ...
    return;

allocMoreStack modifies the code as follows, which leaves the stack pointer at a wrong position when the condition does not hold:

L0:
    move_sp_down;
    ...
    if (...) { move_sp_up; call something() returning to L1; }
L1:
    move_sp_down;
    ...
    move_sp_up;
    return;

comment:7 Changed 3 years ago by igloo

Same as #7510?

comment:8 Changed 3 years ago by erikd

@Igloo I do think this is the same thing.

I currently can't reproduce it with my version or @pho's version of the PPC stack resizing code, but @pho's explanation does seem plausible.

comment:9 Changed 3 years ago by marlowsd@…

commit 03d360f289a1c7e93fedf8cfa274cbe5929cd32c

Author: Simon Marlow <[email protected]>
Date:   Mon Jan 7 12:26:29 2013 +0000

    Fix bugs in allocMoreStack (#7498, #7510)
    
    There were four bugs here.  Clearly I didn't test this enough to
    expose the bugs - it appeared to work on x86/Linux, but completely by
    accident it seems.
    
    1. the delta was wrong by a factor of the slot size (as noted on #7498)
    
    2. we weren't correctly aligning the stack pointer (sp needs to be
    16-byte aligned on x86/x86_64)
    
    3. we were doing the adjustment multiple times in the case of a block
    that was both a return point and a local branch target.  To fix this I
    had to add new shim blocks to adjust the stack pointer, and retarget
    the original branches.  See comment for details.
    
    4. we were doing the adjustment for CALL instructions, which is
    unnecessary and wrong; only JMPs should be preceded by a stack
    adjustment.
    
    (Someone with a PPC box will need to update the PPC version of
    allocMoreStack to fix the above bugs, using the x86 version as a
    guide.)

 compiler/nativeGen/AsmCodeGen.lhs |   10 ++--
 compiler/nativeGen/PPC/Instr.hs   |    7 +-
 compiler/nativeGen/X86/Instr.hs   |  124 +++++++++++++++++++++++++++----------
 3 files changed, 99 insertions(+), 42 deletions(-)

comment:10 Changed 3 years ago by PHO

  • Status changed from new to patch

I ported the above patch to PPC:

% git fetch git://github.com/phonohawk/ghc.git ticket-7498

While x86 version did not seemingly retarget table-branches, I was not sure that was intended or not so I decided to retarget them in my PPC version. At least my patch works for my Darwin/PPC box.

comment:11 Changed 3 years ago by marlowsd@…

commit e19a20488b5b7b412543fb81b81ee9412ef414e6

Author: Simon Marlow <[email protected]>
Date:   Mon Feb 11 10:50:45 2013 +0000

    allocMoreStack: we should be retargetting table jumps too.
    
    Thanks to @PHO on #7498 for pointing this out.

 compiler/nativeGen/X86/Instr.hs |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

comment:12 Changed 3 years ago by simonmar

pushed, thanks. An error when pushing prevented the commit showing up on the ticket:

Unexpected error while processing ticket ID 7498: columns ticket, time, field are not unique
Unexpected error while processing ticket ID 7498: columns ticket, time, field are not unique

So here it is:

commit 36d9ded20c07f6b81271fa248e301cc44f29eff7
Merge: 804d8f6 c1feb5f
Author: Simon Marlow <[email protected]>
Date:   Mon Feb 11 09:23:40 2013 +0000

    Merge remote-tracking branch 'phonohawk/ticket-7498'
    
    * phonohawk/ticket-7498:
      Fix bugs in PPC.Instr.allocMoreStack (#7498)

commit c1feb5f9b82ab05a128ecb7678d2da3db078ff40
Author: PHO <[email protected]>
Date:   Mon Feb 11 13:49:26 2013 +0900

    Fix bugs in PPC.Instr.allocMoreStack (#7498)
    
    This patch is ported from #7510, which fixes the same bug in the x86 nativeGen.

comment:13 Changed 3 years ago by simonmar

  • Resolution set to fixed
  • Status changed from patch to closed
Note: See TracTickets for help on using tickets.