Why doesn’t the simple optimizer fuse casts?

Alexis King lexi.lambda at gmail.com
Mon Apr 27 19:29:19 UTC 2020


This question is spurred by curiosity more than anything else, but
I’ve noticed that the simple optimizer doesn’t fuse nested casts, and
I’m wondering if there’s any reason it couldn’t. To make what I’m
talking about more concrete, suppose we have an expression like this:

    (x |> co) |> sym co

It seems like it would be trivial for simpleOptExpr to fuse the nested
casts to get

    x |> co; sym co

and then the coercion optimizer could get rid of it entirely.
Moreover, this seems within the spirit of the simple optimizer, since
it’s really just “cleaning up” an expression. Is there any reason the
simple optimizer doesn’t do this, or is it just something nobody
implemented?

(For context, I’ve recently been staring at a lot of -ddump-ds output,
and there happen to be a bunch of nested casts in the result that are
really just noise. It would be nice if the simple optimizer got rid of
them for me.)

Alexis


More information about the ghc-devs mailing list