switch index optimization

Jeffrey A Law law@cygnus.com
Sun Jan 25 23:27:00 GMT 1998


  In message < 19980125231458.46648@dot.cygnus.com >you write:
  > > But to do really well, range propagation needs to be done with dataflow
  > > analysis (though in this case you can do it without).
  > 
  > Thus my comment about maybe doing it in jump.  It does some of
  > that sort of thing, and I am half-remembering Jeff doing some
  > work recently in that area for <censored>, such that
  > 
  > 	if (x < 7) {
  > 		if (x == 9) { }
  > 	}
  > 
  > and similar get optimized properly.
Yup.  However, it's become pretty clear to me that the direction I
was heading needs some serious work -- like full blown range checking
code as found in fold_const.c, except on RTL instead of trees (yuk).

It's also not clear how useful that would be in practice; my hacked
up version of cse.c only caught a small number of cases where it could
improve real code instead of contrived example code.

In your case I think you've still got the tree hanging around, so you
might be able to add appropriate code to the range testing code in
fold-const.c to restrict the index instead of doing it in the middle
of the switch code.  If you look at x & 3 as creating a range 0, 1, 2 
then this makes some sense.

jeff



More information about the Gcc mailing list