public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/40907]  New: -O2 generates incorrect code on i386
@ 2009-07-29 17:35 sperber at deinprogramm dot de
  2009-07-29 17:37 ` [Bug c/40907] " sperber at deinprogramm dot de
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: sperber at deinprogramm dot de @ 2009-07-29 17:35 UTC (permalink / raw)
  To: gcc-bugs

When compiling Scheme 48 with -O2, an overflow check in the internal arithmetic
gets elided. This bug showed up sometime after gcc 4.0.1.  It's in 4.4.1, and
in the 4.5-20090723 snapshot.  It's been seen on 32-bit Linux and 32-bit
FreeBSD.

The code snippet in question in c/scheme48vm-32.c is this:

 L12553: {
  b_1970X = arg0K0;
  lo_a_1971X = 65535 & a_1687X;
  lo_b_1972X = 65535 & b_1970X;
  hi_a_1973X = 65535 & (((a_1687X)>>16));
  hi_b_1974X = 65535 & (((b_1970X)>>16));
  lo_c_1975X = SMALL_MULTIPLY(lo_a_1971X, lo_b_1972X);
  v_1976X = SMALL_MULTIPLY(lo_a_1971X, hi_b_1974X);
  v_1977X = SMALL_MULTIPLY(lo_b_1972X, hi_a_1973X);
  mid_c_1978X = v_1976X + v_1977X;
  c_1979X = lo_c_1975X + (((mid_c_1978X)<<16));
  if ((0 < hi_a_1973X)) {
    if ((0 < hi_b_1974X)) {
      val_1980X = integer_multiply(arg2_1113X, y_1114X);
      SvalS = val_1980X;
      Scode_pointerS = ((Scode_pointerS) + 1);
      arg3K0 = (Scode_pointerS);
      goto L32913;}
    else {
      goto L12595;}}
  else {
    goto L12595;}}
 ...
 L12595: {
  if ((536870911 < lo_c_1975X)) {
    val_2153X = integer_multiply(arg2_1113X, y_1114X);
    SvalS = val_2153X;
    Scode_pointerS = ((Scode_pointerS) + 1);
    arg3K0 = (Scode_pointerS);
    goto L32913;}
  else {
    if ((lo_c_1975X < 0)) {

That last test never gets run, and the consequent code does not get run, even
when lo_c_1975X is negative.

I've not been able to boil the code down to a smaller snippet: Smaller programs
containing this code compile OK.


-- 
           Summary: -O2 generates incorrect code on i386
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sperber at deinprogramm dot de
 GCC build triplet: i386-unknown-freebsd7.2
  GCC host triplet: i386-unknown-freebsd7.2
GCC target triplet: i386-unknown-freebsd7.2


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


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

end of thread, other threads:[~2009-07-29 18:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-29 17:35 [Bug c/40907] New: -O2 generates incorrect code on i386 sperber at deinprogramm dot de
2009-07-29 17:37 ` [Bug c/40907] " sperber at deinprogramm dot de
2009-07-29 17:40 ` pinskia at gcc dot gnu dot org
2009-07-29 17:41 ` pinskia at gcc dot gnu dot org
2009-07-29 17:42 ` sperber at deinprogramm dot de
2009-07-29 18:13 ` 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).