[Bug tree-optimization/94779] Bad optimization of simple switch
marxin at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Dec 18 12:07:00 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94779
--- Comment #19 from Martin Liška <marxin at gcc dot gnu.org> ---
>
> One of the work items for the next release is to multi-range enable all
> these consumers that can make use of the information.
I would really appreciate that. I'm don't like integrating VRP into the CSWITCH
pass mainly because it's duplicate work and EVRP runs right before that pass.
And I would prefer a more canonical form of switch statements:
f1(unsigned x) {
if (x >= 3)
__builtin_unreachable();
switch (x) {
case 0:
return 1;
case 1:
return 2;
case 2:
return 3;
}
}
right now we generate:
switch (x)
default:
return 1;
case 1:
return 2;
case 2:
return 3;
I would rather prefer:
switch (x)
case 0:
return 1;
case 1:
return 2;
case 2:
return 3;
default:
__builtin_unreachable ();
Similarly:
int y;
f1(unsigned x) {
if (x == 2)
__builtin_unreachable();
switch (x) {
case 0:
return 1;
case 1:
return 2;
case 2:
return 3;
default:
y = 123;
return 2;
}
}
is transformed into:
switch (x) {
case 0:
return 1;
case 1:
return 2;
default:
y = 123;
return 2;
but I would prefer:
switch (x) {
case 0:
return 1;
case 1:
return 2;
case 2:
__builtin_unreachable ();
default:
y = 123;
return 2;
having that, we could be able to do a CSWITCH transformation.
I'm planning to return to these situations in the next stage1.
More information about the Gcc-bugs
mailing list