This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/84712] New: Missed evaluating to constant at tree level
- From: "prathamesh3492 at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 05 Mar 2018 12:49:22 +0000
- Subject: [Bug tree-optimization/84712] New: Missed evaluating to constant at tree level
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84712
Bug ID: 84712
Summary: Missed evaluating to constant at tree level
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: prathamesh3492 at gcc dot gnu.org
Target Milestone: ---
Hi,
It seems GCC does not evaluate the following function to a constant at the tree
level:
int sum(void)
{
int a[] = {1, 2, 3, -1};
int x = 0;
for (int i = 0; i < 4; i++)
if (a[i] < 0)
break;
else
x += a[i];
return x;
}
optimized dump shows:
sum ()
{
int x;
int a[4];
int _25;
int _33;
int _41;
<bb 2> [local count: 261993005]:
MEM[(int *)&a] = { 1, 2, 3, -1 };
_25 = a[1];
if (_25 < 0)
goto <bb 5>; [7.91%]
else
goto <bb 3>; [92.09%]
<bb 3> [local count: 246744733]:
x_30 = _25 + 1;
_33 = a[2];
if (_33 < 0)
goto <bb 5>; [7.91%]
else
goto <bb 4>; [92.09%]
<bb 4> [local count: 232383926]:
x_38 = x_30 + _33;
_41 = a[3];
if (_41 < 0)
goto <bb 5>; [7.91%]
else
goto <bb 6>; [92.09%]
<bb 5> [local count: 47244641]:
# x_17 = PHI <x_30(3), 1(2), x_38(4)>
goto <bb 7>; [100.00%]
<bb 6> [local count: 218858940]:
x_10 = x_38 + _41;
<bb 7> [local count: 261993005]:
# x_2 = PHI <x_17(5), x_10(6)>
a ={v} {CLOBBER};
return x_2;
}
However at RTL, cprop seems to do the constant folding and set return value
register to 6.
Thanks,
Prathamesh