case opimizations

Henry Cejtin henry@sourcelight.com
Mon, 10 Dec 2001 15:19:12 -0600


I don't remember Richard talking about this.

Note  for  case  statements  one thing that has been in C compilers since the
olden days has been to handle cases that have a common tail.  I.e.,

    switch (expr) {
    ...
    case ???:
            stuff
            more-stuff
            break;
    ...
    case ???:
            different stuff
            more-stuff
            break;
    ...
    }

will cause one of the cases to end with a branch to  the  more-stuff  in  the
other.  (This also handles the case of different cases with identical bodys.)

I don't know how much this happens in ML code because of the less  imperative
nature, but it might be a win.  Note, the win is I-cache space more than code
space.  It introduces an extra branch, but  it  is  unconditional  so  branch
prediction should be perfect.

Perhaps  this  would  compensate  for  some  code blow-up from duplication to
remember known information.