[Bug tree-optimization/58774] tree-switch-conversion doesn't with content in default scase
ben.maurer at gmail dot com
gcc-bugzilla@gcc.gnu.org
Fri Oct 18 17:18:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58774
--- Comment #2 from Ben Maurer <ben.maurer at gmail dot com> ---
I think there might be multiple appropriate transformations. In the
switchwithnoprint example I attached, it is currently compiled as:
<switchwithnoprint>:
sub $0x1,%edi
xor %eax,%eax
cmp $0x5,%edi
ja RETURN
mov 0x400740(,%rdi,4),%eax
RETURN: repz retq
A good transformation for the switchwithprint function might be to make the
RETURN label do the printf. On the other hand, the switch case with a
non-trivial function might not be as clean as this. Eg, you could have:
switch(val) {
case 1: return 1;
case 2: return 2;
case 3: printf("hello");
case 4: return 4;
}
In this case you could do something like:
struct {
bool is_code;
union {int ret; void* jmp};
} actions[] = ...
if (val >= 1 && val <= 4) {
auto action = actions[val];
if (action.is_code) goto action.jmp;
else return action.ret;
}
In theory, you might even be able to avoid having the is_code value if you knew
that the ret and jmp values never overlapped (eg, if (action >
MAX_POSSIBLE_RETURN_VALUE) goto (void*) action).
More information about the Gcc-bugs
mailing list