Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: Gerald Feldman <gaf@highway1.com>
Subject: Re: horrible "cc -O" bug (DU 3.2c)
Date: 1997/05/10	[thread overview]
Message-ID: <3374892D.5E93@highway1.com> (raw)
In-Reply-To: 5kvqsu$18d$1@news.iastate.edu


John Hascall wrote:
> 
> Mark Bartelt <mark@cita.utoronto.ca> wrote:
> }Someone just called my attention to a really disturbing
> }bug in DEC's C compiler.  It seems that if a program is
> }compiled with "-O", then evaluation of "expr1 && expr2"
> }is botched:  Even when expr1 evaluates to 0, expr2 gets
> }evaluated anyway!
> }
> }The implications of this bug are rather staggering; for
> }example, what if expr2 has side-effects?  Gack.
> }
> }The bug seems to appear only when "-O" is used.  Here's
> }a short example program.  It generates a floating-point
> }exception when compiled with "-O".  (It shouldn't, since
> }the expression to the right of the "&&" should never be
> }evaluated.)
> 
>     Gack!  Here's the code w/o and with -O:
> 
> #    6    if ( flag && 1/x > y ) x = 0;
> 
>      ldl     $1,   16($sp)                 ldl     $1,   48($sp)
>      beq     $1,   $32                     ldit    $f10, 1.0000000000000000e+00
>      ldit    $f10, 1.0000000000000000e+00  divt    $f10, $f17, $f11
>      ldt     $f11, 24($sp)                 ldt     $f12, 64($sp)
>      divt    $f10, $f11, $f12              cmptlt  $f12, $f11, $f13
>      ldt     $f13, 32($sp)                 cpys    $f17, $f17, $f14
>      cmptlt  $f13, $f12, $f14              fcmovne $f13, $f31, $f14
>      fbeq    $f14, $32                     stq     $1,   32($sp)
>      stt     $f31, 24($sp)                 ldt     $f15, 32($sp)
> $32:                                       cpys    $f14, $f14, $f0
>                                            fcmoveq $f15, $f17, $f0
> 
>    Obviously they are trying to use conditional
>    moves to avoid branches - but this is really
>    wrong...
Interesting. BTW: The cc command in V3.2c is the old MIPS based compiler
that has been retired. The cc -migrate is the newer DECC compiler. I am
not sure thnat this is really a bug. As long as the evaluation does not
cause any side effects. Remember that on the Alpha chip, 2 or 4
instaructions can be executed at the same time. (eg. dual or quad
issue). even with the branch code, the float instructions will have been
prefetched, and may be executed before the branch completes. The code is
only wrong if it were to cause a floating exception when flag is zero,
or if the cost of evaluating argument 2 is higher than the conditional
branch. 

-- 
+----------------------------------------------+
|  Jerry Feldman <gaf@highway1.com>            |
|  Boston Computer Solutions and Consulting    |
|  http://gaf.ne.highway1.com/                 |
+----------------------------------------------+



  reply	other threads:[~1997-05-10  4:00 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-05-09  4:00 horrible "cc -O" bug (DU 3.2c) Mark Bartelt
1997-05-09  4:00 ` Jonathan Rozes
1997-05-09  4:00 ` John Hascall
1997-05-10  4:00   ` Gerald Feldman [this message]
1997-05-11  4:00   ` Roy Smith
1997-05-11  4:00     ` Gerald A. Feldman
1997-05-11  4:00       ` Roy Smith
1997-05-12  4:00         ` Mark Bartelt
1997-05-12  4:00           ` Andy Isaacson
1997-05-12  4:00             ` John Reinitz
1997-05-13  4:00             ` Mark Bartelt
1997-05-12  4:00         ` Jeff Sullivan USG
1997-05-12  4:00           ` Gerald A. Feldman
1997-05-12  4:00       ` Bob Vickers
1997-05-12  4:00       ` Jeff Sullivan USG
1997-05-12  4:00       ` Peter Kocourek
1997-05-11  4:00     ` Michael C. Grant
     [not found] ` <5l7hap$7la@usenet.pa.dec.com>
1997-05-12  4:00   ` Gerald A. Feldman
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox