CASESI: GCC is optimising away my cases

Paul Webster pmw@uk.research.att.com
Tue Dec 14 09:20:00 GMT 1999


Hi all,

I'm trying to port the GCC compiler to a new machine description. I've got the 
basics working and am now trying to optimise case statements when using a 
dispatch table.

I've created a `casesi' pattern which outputs code for jumping via the table.
This produces the expected code. However, when I run the compiler with any
optimisation enabled, it removes the blocks of code referred to in the dispatch
table.

What it looks like is happening is that the jump optimisation cannot find a
jump which refers to the routines (as they are done indirectly via the dispatch
table), so it decides it can happily remove the code as it can never be called.
The label entries are still in the dispatch table, but are no longer defined.
If I have a default case, this is still maintained, as my bounds-checking branch
refers to this.

I've looked through the supplied machine descriptions and headers and cannot
see anything obvious that I am missing. What I think I need to do is mark the
case routines as being used by the main body of the code. I've seen comments
to the effect that this can be done by generating dummy jumps to each of the
cases, but I cannot find a clear example of how I can do this. If I remove the
`casesi' pattern and define a `tablejump' pattern the cases are not optimised
away, but the jump code is then non-optimal!

Could anyone offer any suggestions on the best way I can stop GCC optimising
this code away!

Thanks in advance,

    Paul


==============================================================================
                          AT&T Laboratories Cambridge
------------------------------------------------------------------------------
    Dr. Paul Webster, 24a Trumpington Street, Cambridge, CB2 1QA, England.
==============================================================================


More information about the Gcc-help mailing list