https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118527
Bug ID: 118527
Summary: When a loop is unlooped due to sccvn, its profile is
not updated
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: dizhao at os dot amperecomputing.com
Target Milestone: ---
For the tiny example below, with compile command "gcc -O1
-fdisable-tree-ch2 -fenable-tree-pre -fdisable-tree-fre1
-fdisable-tree-fre3 -c", the innermost loop is identified
by pass pre to be not iterating. But the profile counts of
the basic blocks are not updated accordingly.
void
foo (int a, int b)
{
for (int i = 0; i < 100; i++)
{
int j = 100 - b - a;
do
{
if ((i + j) % 5 != 0)
array[i][j] += 10;
++j;
if (100 - b - a < j)
break;
}
while (1);
array[i][100 - a] += 8;
array[i][100 - b] -= 9;
}
}
Gimple code in 151t.walloca2:
void foo (int a, int b)
{
...
<bb 2> [local count: 1193046]:
goto <bb 8>; [100.00%]
<bb 3> [local count: 118111600]:
_1 = 100 - b_22(D);
j_24 = _1 - a_23(D);
<bb 4> [local count: 1073741824]:
# j_17 = PHI <j_24(3), j_26(10)>
_2 = i_16 + j_17;
_3 = _2 % 5;
if (_3 != 0)
goto <bb 5>; [50.00%]
else
goto <bb 6>; [50.00%]
<bb 5> [local count: 536870912]:
_4 = array[i_16][j_17];
_5 = _4 + 10;
array[i_16][j_17] = _5;
<bb 6> [local count: 1073741824]:
j_26 = j_17 + 1;
if (j_24 < j_26)
goto <bb 7>; [11.00%]
else
goto <bb 10>; [89.00%]
<bb 10> [local count: 955630224]:
goto <bb 4>; [100.00%]
<bb 7> [local count: 118111600]:
_8 = 100 - a_23(D);
_9 = array[i_16][_8];
_11 = _9 + 8;
array[i_16][_8] = _11;
_13 = array[i_16][_1];
_15 = _13 + 4294967287;
array[i_16][_1] = _15;
i_29 = i_16 + 1;
<bb 8> [local count: 119304646]:
# i_16 = PHI <0(2), i_29(7)>
if (i_16 <= 99)
goto <bb 3>; [99.00%]
else
goto <bb 9>; [1.00%]
<bb 9> [local count: 1193046]:
return;
}
Gimple code in 152t.pre:
void foo (int a, int b)
{
...
<bb 2> [local count: 1193046]:
goto <bb 6>; [100.00%]
<bb 3> [local count: 118111600]:
_1 = 100 - b_22(D);
j_24 = _1 - a_23(D);
_2 = i_16 + j_24;
_3 = _2 % 5;
if (_3 != 0)
goto <bb 4>; [50.00%]
else
goto <bb 5>; [50.00%]
<bb 4> [local count: 536870912]:
_4 = array[i_16][j_24];
_5 = _4 + 10;
array[i_16][j_24] = _5;
<bb 5> [local count: 1073741824]: //This is too big.
//(Should be 118111600)
j_26 = j_24 + 1;
_8 = 100 - a_23(D);
_9 = array[i_16][_8];
_11 = _9 + 8;
...
}