case optimizations

Stephen Weeks MLton@sourcelight.com
Mon, 10 Dec 2001 11:10:55 -0800


> > case x of A => L1 | B => L2 | _ => L1
> > -->
> > case x of B => L2 | _ => L1
> > 
> > 
> > case x of A => L1 | B => L2 | C => L2
> > -->
> > case x of A => L1 | _ => L2  
> > if B and C are non-value-carrying
> 
> These two aren't that hard; could they go in the shrinker?
> I say that, because they are completely local transformations -- it
> doesn't matter what is passed for x.

Yep.  The shrinker can (and will) do these.  I will have to add the
datatypes in addition to the globals as an arg, but no big deal.

> KnownCase is going to need an inliner like metric. 
...
> The more troubling cases are when we have blocks like
>  LX (??) = 
>    s1
>    s2
>    ...
>    sN
>    case x of A => LA | B => LB | ... | _ => LD
> 
> If there is a place where x is known to be an A and place where x is known
> to be B, then do we want to duplicate s1...sN?  Maybe up to some small
> value of N, but certainly not in all cases.

Yeah, I'd leave this out for now, but I agree it is useful.  I
remember Richard Kelsey talking about this years ago at NEC, but I
don't remember anything concrete.  Henry or Suresh, any pointers or
ideas?