Changes between Version 3 and Version 4 of Commentary/Compiler/NewCodeGenStupidity


Ignore:
Timestamp:
Mar 23, 2011 1:11:18 PM (4 years ago)
Author:
ezyang
Comment:

more things wrong

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/Compiler/NewCodeGenStupidity

    v3 v4  
    8181
    8282This is mentioned at the very top of `cmm-notes`.
     83
     84== Sp is generally stupid ==
     85
     86Here is an optimized C-- sample from `arr016.hs`.
     87
     88{{{
     89Main.D:Arbitrary_entry()
     90        { [const 131084;, const 0;, const 15;]
     91        }
     92    c7J5:
     93        _B1::I32 = I32[Sp + 4];
     94        _B2::I32 = I32[Sp + 0];
     95        if ((Sp + 0) < I32[BaseReg + 84]) goto u7Jf;
     96        Sp = Sp + 12;
     97        Hp = Hp + 12;
     98        if (Hp > I32[BaseReg + 92]) goto c7Jc;
     99        I32[Hp - 8] = Main.D:Arbitrary_con_info;
     100        I32[Hp - 4] = _B2::I32;
     101        I32[Hp + 0] = _B1::I32;
     102        _c7J4::I32 = Hp - 8;
     103        _c7J4::I32 = _c7J4::I32 + 1;
     104        R1 = _c7J4::I32;
     105        Sp = Sp - 4;
     106        jump (I32[Sp + 0]) ();
     107    u7Jf:
     108        Sp = Sp + 12;
     109        goto c7Jd;
     110    c7Jc:
     111        I32[BaseReg + 112] = 12;
     112        goto c7Jd;
     113    c7Jd:
     114        R1 = Main.D:Arbitrary_closure;
     115        Sp = Sp - 12;
     116        jump (I32[BaseReg - 4]) ();
     117}
     118}}}
     119
     120Compare with the old code:
     121
     122{{{
     123Main.D:Arbitrary_entry()
     124        { [const 131084;, const 0;, const 15;]
     125        }
     126    c4pX:
     127        Hp = Hp + 12;
     128        if (Hp > I32[BaseReg + 92]) goto c4pU;
     129        I32[Hp - 8] = Main.D:Arbitrary_con_info;
     130        I32[Hp - 4] = I32[Sp + 0];
     131        I32[Hp + 0] = I32[Sp + 4];
     132        R1 = Hp - 7;
     133        Sp = Sp + 8;
     134        jump (I32[Sp + 0]) ();
     135    c4pV:
     136        R1 = Main.D:Arbitrary_closure;
     137        jump (I32[BaseReg - 4]) ();
     138    c4pU:
     139        I32[BaseReg + 112] = 12;
     140        goto c4pV;
     141}
     142}}}
     143
     144There are a lot of things wrong
     145
     146 - We do an unnecessary stack check on entry to this function
     147 - Sp should be bumped before the stack check (but we need this fishy code due to ncg spilling before the check)
     148 - The `R1` assignment is silly (although that's my fault; I should probably fix up the offending patch)
     149 - Sp is getting bumped too much, and then being adjusted back down again