https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126236
--- Comment #2 from ktkachov at gcc dot gnu.org ---
(In reply to Richard Biener from comment #1)
> pass_duplicate_computed_gotos is an RTL pass, I think if it can be made to
> handle casei & friends that would be nice - possibly controlled by the
> target and/or a user switch.
I had looked into doing it at RTL but to get it working reliably it needed
>1000 lines of code. Mostly because it needed to handle things like:
- Decode casesi patterns, UNSPEC_CASESI, index bias, bounds, default behavior,
and table ownership
- As the duplicate_computed_gotos pass is done post-reload no new pseudos are
available. The pass must find safe hard registers and validate every
synthesized instruction
- Convert the native relative ADDR_DIFF_VEC table into an absolute
label-address table
- Repair debug locations referring to hard registers overwritten by the new
sequence
- For aarch64, teach BTI handling that the new absolute table labels are
indirect-jump targets
What about we do some of the processing in lower_switch to transform:
for (;;)
{
opcode = *pc++;
switch (opcode)
{
case OP_ADD:
/* ADD handler. */
...
break;
case OP_LOAD:
/* LOAD handler. */
...
break;
}
}
into:
dispatch:
opcode = *pc++
slot = normalize(opcode)
if slot is out of range
goto default_handler
target = label_table[slot]
goto target // GIMPLE_GOTO
op_add:
...
goto dispatch
op_load:
...
goto dispatch
label_table = { &op_add, &op_load, &default_handler, ... }
Then lower GIMPLE_GOTO as an ordinary indirect_jump. Then the RTL computed goto
copier can handle the rest?