This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [tree-ssa] RFC: Making control flow more explicit


Diego Novillo <dnovillo@redhat.com> writes:


> [SWITCH_EXPR] I'm undecided.  The easiest is to generate a decision
> tree, but we may also want to generate a jump table.  For now, I was
> thinking on doing a decision tree with if's.  I mainly want to
> prevent the optimizers from having to deal with SWITCH_EXPR which
> has been a source of some problems.

I'll point out that the "jump table" notion is highly
machine-specific, so should probably be reserved to RTL, and
furthermore that it would be nice to be able to optimize an 
if/else if/else if/... chain in the user's code to a more
efficient decision tree, or a jump table, where that makes sense.
Intuitively, I bet if-chains are easier to cope with for the tree
optimizers.

So my vote is for lowering SWITCH_EXPR to a decision tree in the tree
optimizers, and then having the smarts in the tree->RTL converter to
generate a jump table from that.

Another optimization which would be nice to be able to do in this
context is: given

int foo(int x) {
  switch (x) {
    case 'a': return 23;
    case 'b': return 34;
    case 'c': return 45;
    case 'f': return 56;
    default:  return 0;
  }
}

generate

int foo(int x) {
  static char t[] = {
    23, 34, 45, 0, 0, 56
  };
  x -= 'a';
  if ((unsigned int)x > 6U) return 0;
  return (int)t[x];
}

This can be a serious size reduction, but writing out the switch
statement is more portable and arguably more readable (which is why
the programmer might not have done it themselves).

zw


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]