switch index optimization

Lassi A. Tuura Lassi.Tuura@cern.ch
Tue Jan 27 07:35:00 GMT 1998


On Mon, 26 Jan 1998, Jeffrey A Law wrote:
>   > 	if (x < 7) { if (x == 9) { } }
> 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.

I would think this kind of an optimisation would pay off for C++ code
where there are multitudes of small inlined methods.  The reason is that
the methods cannot always tell what state the object is in and hence
the body must be guarded with checks like this:

  if (! m_data) {
     // initialise `m_data' to something
  }
  // real code here

As the methods get inlined, these checks can repeat several times even if
it may be possible to prove that none of them (or only the first one)
needs to be evaluated.  This may, again, result in significant dead code
elimination and opportunities for further optimisation. 

It may well be that in C this optimisation does not produce any
significant benefits because of the way code gets written: small inlines
just aren't used all that much. 

Cheers,
//lat
--
Lassi.Tuura@cern.ch          There's no sunrise without a night




More information about the Gcc mailing list