Hmm, this is both a VRP bug and a folding bug. Even though a is VARYING, we
know the that a*a will
always be postive (this with -fno-wrapv which is default for C, C++ and
fortran).
void link_error(void);
void f(int a)
{
int b = a;
b*=a;
if (b < 0)
link_error();
}
---
There should be no references to link_error().
There is another way of fixing this via the fold:
void link_error(void);
void f(int a)
{
if (a*a < 0)
link_error();
}
But that will miss:
void link_error(void);
void f(int a)
{
if (a*a*a*a*a*a < 0)
link_error();
}
---
Yes that is most likely to overflow but that is the whole point of -fno-wrapv.
Also ICC does not do this optimization at all.
--
Summary: a*a (for signed ints with -fno-wrapv) is always postive
Product: gcc
Version: 4.1.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P2
Component: tree-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: pinskia at gcc dot gnu dot org
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23471