https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91089
Bug ID: 91089
Summary: IPA-cp does setup proper cost model for switch default
case in function versioning
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: ipa
Assignee: unassigned at gcc dot gnu.org
Reporter: fxue at os dot amperecomputing.com
CC: marxin at gcc dot gnu.org
Target Milestone: ---
IPA-cp always adds execution cost of switch default case into cost evaluation
for other switch case, which might miss opportunities of function versioning
when only certain case is proved to be executed after constant propagation.
The following is an example, compiled with "-O3 -fno-inline".
It is reasonable to make a function versioning for callee when "v=1", but
actually it does not happen. And if we replace "default" with "case = 4",
it clones the function as we expect.
In some situations, we can deduce a relative small execution predicate
for default case. If all switch cases are in a continuous value range, we
can use compare to range low and high bound to mark default switch case.
Additionally, range analysis can also give us more information to simplify
the predicate.
int foo();
int callee(int v)
{
int i = 0;
switch (v)
{
case 1:
i = 3;
break;
case 2:
i = 9;
break;
default:
foo();
foo();
foo();
foo();
foo();
foo();
foo();
foo();
foo();
}
return i;
}
int caller()
{
return callee (1);
}