Implement forward substitution of constants in the Cmm mini-inliner
authorJohan Tibell <johan.tibell@gmail.com>
Fri, 6 May 2011 12:13:03 +0000 (14:13 +0200)
committerSimon Marlow <marlowsd@gmail.com>
Wed, 1 Jun 2011 09:56:05 +0000 (10:56 +0100)
commitea44eadfb9d269d06b889fbfe41286bf0c7a730d
tree3c2492a9e7e2e4a29665c469872fe4bec01fcac7
parentef062308fb38b2cbbf30a0057bd839b5382648a4
Implement forward substitution of constants in the Cmm mini-inliner

Currently the mini-inliner would only forward substitute assignments
to registers that were used exactly once, to not risk duplicating
computation.  For constants there's no such risk so we always
substitute.  Prior to the change the Cmm

    fn
    {
        bits64 a, b;

        a = 1;
        b = a + a;
        RET_N(b);
    }

would be optimized as

    fn()    { []
            }
        ca: _cb::I64 = 1;
            R1 = _cb::I64 + _cb::I64;
            jump (I64[Sp + 0]) ();
    }

but after it would be optimized as

    fn()    { []
            }
        ca: R1 = 2;
            jump (I64[Sp + 0]) ();
    }

Note that this pass does not deal with the now dead assignment.
compiler/cmm/CmmOpt.hs