public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/30364]  New: Wrong variable ranges due to constant folding
@ 2007-01-04  9:16 guillaume dot melquiond at ens-lyon dot fr
  2007-01-04  9:30 ` [Bug middle-end/30364] [4.1/4.2/4.3 Regression] " pinskia at gcc dot gnu dot org
                   ` (21 more replies)
  0 siblings, 22 replies; 23+ messages in thread
From: guillaume dot melquiond at ens-lyon dot fr @ 2007-01-04  9:16 UTC (permalink / raw)
  To: gcc-bugs

Testcase: (compiled with -O2 at least)

int f(int a, int b)
{
  if (a > 0x7FFFFFF0) return 0;
  if (b > 0x7FFFFFF0) return 0;

  int c = (a - 20) + (b - 20);
  return c > 0x7FFFFFF0;
}

GCC 4.1.2 and 4.3.0 (snapshot from 2006-12-17) optimizes the whole function to
a single "return 0;". This would be correct if the function was actually
written with "c = a + b - 40" under a non-overflow assumption. GCC could indeed
deduce that c is no bigger than 0x7FFFFFFF - 40.

But as the function was originally written, this property does not hold any
longer. For example, a = 0x7FFFFFF0 and b = 41 will not cause any overflow
during computations, and the last conditional shall hence evaluate to true.

The problem is that GCC performs VRP with C language semantic (undefined
behavior on overflow) on code that is no longer the input as written by the
user; so this semantic is not valid at that point. The user input should not
have undergone a transformation based on associativity.

Tested with Debian packages. GCC 3.3.6, 3.4.6, and 4.0.4 generate correct code.
GCC 4.1.2 and 4.3.0 generates wrong code. As the expression "a + b - 40" is
generated early, I suppose any GCC with VRP would produce wrong code for this
testcase.


-- 
           Summary: Wrong variable ranges due to constant folding
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: guillaume dot melquiond at ens-lyon dot fr


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30364


^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2007-08-24 16:40 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-04  9:16 [Bug c/30364] New: Wrong variable ranges due to constant folding guillaume dot melquiond at ens-lyon dot fr
2007-01-04  9:30 ` [Bug middle-end/30364] [4.1/4.2/4.3 Regression] " pinskia at gcc dot gnu dot org
2007-01-04 10:15 ` guillaume dot melquiond at ens-lyon dot fr
2007-01-04 10:23 ` pinskia at gcc dot gnu dot org
2007-01-04 10:26 ` pinskia at gcc dot gnu dot org
2007-01-04 10:40 ` pinskia at gcc dot gnu dot org
2007-01-04 11:25 ` guillaume dot melquiond at ens-lyon dot fr
2007-01-05 19:06 ` jakub at gcc dot gnu dot org
2007-01-05 19:58 ` pinskia at gcc dot gnu dot org
2007-01-05 20:32 ` pinskia at gcc dot gnu dot org
2007-01-05 21:06 ` gdr at integrable-solutions dot net
2007-01-05 21:09 ` gdr at integrable-solutions dot net
2007-02-05  5:50 ` mmitchel at gcc dot gnu dot org
2007-02-14  9:03 ` mmitchel at gcc dot gnu dot org
2007-02-21 14:24 ` rguenth at gcc dot gnu dot org
2007-02-28 21:57 ` rguenth at gcc dot gnu dot org
2007-02-28 23:03 ` [Bug middle-end/30364] [4.1/4.2 " rguenth at gcc dot gnu dot org
2007-03-05 13:15 ` rguenth at gcc dot gnu dot org
2007-03-05 13:17 ` [Bug middle-end/30364] [4.1 " rguenth at gcc dot gnu dot org
2007-03-15 18:09 ` rguenth at gcc dot gnu dot org
2007-03-15 18:10 ` rguenth at gcc dot gnu dot org
2007-08-24 16:33 ` jakub at gcc dot gnu dot org
2007-08-24 16:40 ` rguenth at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).