This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Optimizer Bug with gcc-2.95 on Solaris-(2.6|7)


Jürgen Zimmermann wrote:

> The following code was found in a Linux Usenet-group, but it turned out,
> that gcc-2.95 on Solaris-2.6 and
> Solaris-7 shows the same behaviour.
> CFLAGS="" and CFLAGS="-O3" produce correct results,
> CFLAGS="-O" or CFLAGS="-O2" produce false results.

Yep, same over here - the code fails on PowerPC, i[3456]86 and now also
SPARC.  This is probably because it is a defect in the "middle-end",
i.e. the part of the compiler past the frontends but before the target
specific parts.

> #include <stdio.h>
> 
> /* If one=1, then the output should be: bit&1 */
> unsigned test(unsigned one , unsigned  bit)
> {
>     unsigned val=  bit & 1;
>     unsigned zero= one >> 1;
> 
>     val++;
>     return zero + ( val>> 1 );
> }
> 
> int main()
> {
>   printf("ret=%d\n", test(1,0)); /* should print 0 */
>   printf("ret=%d\n", test(1,1)); /* should print 1 */
>   printf("ret=%d\n", test(1,65535)); /* should print 1 */
> 
>   return 0;
> }

To prove that it is frontend independent, here's the Fortran variant:

      INTEGER FUNCTION TEST(ONE, BIT)
      INTEGER ONE, BIT
      INTEGER VAL, ZERO
      VAL  = IAND(BIT, 1)
      ZERO = ISHFT(ONE, -1)
      VAL  = VAL + 1
      TEST = ZERO + ISHFT(VAL, -1)
      END
      PROGRAM AAP
      INTEGER TEST
      PRINT*,TEST(1,0)
      PRINT*,TEST(1,1)
      PRINT*,TEST(1,65535)
      END

This is being investigated by Franz Sirl - see progress reports on the
mailing list gcc@gcc.gnu.org with subject "Deadly optimization bug (all
gcc versions!)".

HTH,

-- 
Toon Moene (toon@moene.indiv.nluug.nl)
Saturnushof 14, 3738 XG  Maartensdijk, The Netherlands
Phone: +31 346 214290; Fax: +31 346 214286
GNU Fortran: http://world.std.com/~burley/g77.html


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]