This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/23471] New: a*a (for signed ints with -fno-wrapv) is always postive
- From: "pinskia at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 18 Aug 2005 23:50:40 -0000
- Subject: [Bug tree-optimization/23471] New: a*a (for signed ints with -fno-wrapv) is always postive
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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