Changes between Version 18 and Version 19 of Commentary/Compiler/NewCodeGenStupidity


Ignore:
Timestamp:
Apr 16, 2011 7:28:41 PM (4 years ago)
Author:
ezyang
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/Compiler/NewCodeGenStupidity

    v18 v19  
    107107}}}
    108108
    109 This is mentioned at the very top of `cmm-notes`.
     109This is mentioned at the very top of `cmm-notes`. This was a bug in the stack layout code that I have fixed.
    110110
    111111== Sp is generally stupid ==
     
    168168}}}
    169169
    170 There are a lot of things wrong
    171 
    172  - We do an unnecessary stack check on entry to this function
    173  - Sp should be bumped before the stack check (but we need this fishy code due to ncg spilling before the check)
    174  - Sp is getting bumped too much, and then being adjusted back down again
     170The unfixed problem is this (some of the other problems were already addressed): we do an unnecessary stack check on entry to this function. We should eliminate the stack check (and by dead code analysis, the GC call) in such cases.
    175171
    176172This pattern essentially happens for every function, since we always assign incoming parameters to temporary variables before doing anything.
     
    189185
    190186R1 and Sp probably don't clobber each other, so we ought to use _cPY twice in quick succession. Fortunately stg_IND_STATIC_info is a constant so in this case the optimization doesn't help to much, but in other cases it might make sense. TODO Find better example
     187
     188== Stack space overuse ==
     189
     190`T1969.hs` demonstrates this:
     191
     192{{{
     193 Simp.c_entry()
     194         { update_frame: <none>
     195           has static closure: True type: 0
     196           desc: 0
     197           tag: 15
     198           ptrs: 0
     199           nptrs: 0
     200           srt: (srt_Sc2_srt,0,3)
     201           fun_type: 5
     202           arity: 1
     203           slow: Simp.c_slow
     204         }
     205     cbG:
     206         _sbe::I32 = I32[Sp + 0];
     207         if (Sp - 4 < SpLim) goto cbN;
     208         // outOfLine should follow:
     209         if (_sbe::I32 & 3 != 0) goto cbP;
     210         // emitCall: Sequel: Assign
     211         R1 = _sbe::I32;
     212         I32[Sp - 4] = block_cbA_info;
     213         Sp = Sp - 4;
     214         jump I32[_sbe::I32] ();
     215     cbN:
     216         // outOfLine here
     217         R1 = Simp.c_closure;
     218         jump stg_gc_fun ();
     219     cbP:
     220         // emitReturn: Sequel: Assign
     221         _sbg::I32 = _sbe::I32;
     222         Sp = Sp + 4;
     223         jump block_cbR_entry ();
     224 }
     225}}}
     226
     227The call area for the jump in cbG is using an extra word on the stack, but in fact Sp + 0 at the entry of the function immediately becomes dead after the assignment, so we ought to be able to save some space in our layout. Simon Marlow suggests we distinguish between the return address and the old call area; need to talk to SPJ about fixing this.