Bug 73488 - g77 -O2 miscompiles floating point multiplication on alpha
g77 -O2 miscompiles floating point multiplication on alpha
Status: CLOSED CURRENTRELEASE
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
7.2
alpha Linux
high Severity high
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2002-09-05 06:48 EDT by Pawel Salek
Modified: 2005-10-31 17:00 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2002-12-15 17:52:53 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:


Attachments (Terms of Use)

  None (edit)
Description Pawel Salek 2002-09-05 06:48:06 EDT
Description of problem:
Following line DR  = DR1*DR2 produces 0 despite the fact that DR1 and DR2 are
non-zero (DR1=DFLOAT(1), DR2 is of order 1.91154326E-05) when compiled with -O2.
-O produces correct code.


How reproducible:
Always

Steps to Reproduce:
Bit difficult because I can see it only in a larger program. I think this
multiplication instruction "interacts" with the surrounding instructions.

It took me a two days to find the difference between results generated with
these two options.

Additional info: gcc-g77-2.96-108.7.2

Following chunk:
               DR1 = DREAL(T+1)
               DR2 = ODCUND(A-1,0,T+1,0,0,2)
               DR  = DR1*DR2
               ODCUND(A,0,T,0,0,2) = ODCUND(A,0,T,0,0,2)+DR
is compiled with -O2 to incorrect code:
	ldgp $29,0($26)
	stl $11,352($30)
	lds $f12,352($30)
	ldq $1,280($30)
	ldl $2,224($30)
	cvtlq $f12,$f10
	ldq $3,328($30)
	s8addq $2,$1,$2
	addq $2,$12,$1
	addq $1,$14,$1
	addq $1,$3,$1
	cvtqt $f10,$f13
	trapb
	addq $2,$13,$2
	ldt $f10,8($1)
	addq $2,$14,$2
	lda $2,16($2)
	addq $3,$2,$2
	ldt $f12,0($2)
	multsu $f13,$f10,$f11
	stt $f11,248($30)
	trapb
	addtsu $f12,$f11,$f10
	stt $f10,0($2)
	trapb
but with -O to correct code:
        ldgp $29,0($26)
        lds $f13,336($30)
        cvtlq $f13,$f10
        cvtqt $f10,$f11
        ldl $2,224($30)
        trapb
        s8addq $2,$15,$2
        addq $2,$12,$1
        addq $1,$14,$1
        ldq $3,320($30)
        addq $1,$3,$1
        ldt $f10,8($1)
        multsu $f11,$f10,$f12
        trapb
        fmov $f12,$f11
        stt $f11,248($30)
	addq $2,$10,$2
        addq $2,$14,$2
		   lda $2,16($2)
	addq $3,$2,$2
        ldt $f10,0($2)
        addtsu $f11,$f10,$f13
				trapb
        fmov $f13,$f10
	   stt $f10,0($2)

If you need more info, help with debugging, feel free to contact me.
Comment 1 Pawel Salek 2002-09-05 08:37:19 EDT
It seems that handling of underflows is incorrect with -O2. I attach a test
program to be compiled with g77 -O2 -mieee that 
should produce 
 Ax:  0.  0.
 Ax:  2.17292373E-311  2.17292373E-311
 Ax:  1.91154329E-05  1.91154329E-05
 Ax:  4.77448489E-314  4.77448489E-314
 Ax:  1.48219694E-323  1.48219694E-323
but produces
 Ax:  0.  0.
 Ax:  0.  2.17292373E-311
 Ax:  0.  1.91154329E-05
 Ax:  0.  4.77448489E-314
 Ax:  0.  1.48219694E-323

value of 1.91154329E-05 is "rounded" to 0.
Comment 2 Pawel Salek 2002-09-05 08:39:50 EDT
I cannot attach a document, bugzilla claims that I am not logged in. I paste the
code here:
c     g77 -O3 -mieee prog.f && ./a.out
      SUBROUTINE ONEODC(ODCUND,JMAXAP,JMAXBP,JMAXTP,JMAXD,JMAXM,FAC,
     &                  EXPPI,CORPX,CORPY,CORPZ,IPRINT)
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      INTEGER T, A, B, AB
      DIMENSION ODCUND(-2:JMAXAP+1,-1:JMAXBP+1,-2:JMAXTP,
     &                 0:JMAXD,0:JMAXM,3)
      COMMON /ONECOM/ CORAX,CORAY,CORAZ,CORBX,CORBY,CORBZ

      PAX = CORPX - CORAX
      PAY = CORPY - CORAY
      PAZ = CORPZ - CORAZ
      PBX = CORPX - CORBX
      PBY = CORPY - CORBY
      PBZ = CORPZ - CORBZ
      EXPPIH = EXPPI/2D0
      DO 100 A = 0, JMAXAP
         IF (IPRINT .GE. 20)write(LUPRI,*)'A1:',ODCUND(2,0,0,0,0,2), A
          IF (A .EQ. 0) THEN
            ODCUND(0,0,0,0,0,1) = FAC
            ODCUND(0,0,0,0,0,2) = FAC
         ELSE
            DO 200 T = 0, A
               ODCUND(A,0,T,0,0,1) = EXPPIH*ODCUND(A-1,0,T-1,0,0,1)
     *                                + PAX*ODCUND(A-1,0,T  ,0,0,1)
     *                        + DFLOAT(T+1)*ODCUND(A-1,0,T+1,0,0,1)
               ODCUND(A,0,T,0,0,2) = EXPPIH*ODCUND(A-1,0,T-1,0,0,2)
     *                                + PAY*ODCUND(A-1,0,T  ,0,0,2)
               DR  = DFLOAT(T+1)*ODCUND(A-1,0,T+1,0,0,2)
               ODCUND(A,0,T,0,0,2) = ODCUND(A,0,T,0,0,2)+DR
               print *,'Ax:', DR,DFLOAT(T+1)*ODCUND(A-1,0,T+1,0,0,2)
  200       CONTINUE
         END IF
  100 CONTINUE
      RETURN
      END
      PROGRAM aaa
      IMPLICIT DOUBLE PRECISION (A-H,O-Z)
      DOUBLE PRECISION ODCUND(1000),A,B,C,D,E
      COMMON /ONECOM/ CORAX,CORAY,CORAZ,CORBX,CORBY,CORBZ
      CORAX = 0.5D0
      CORAY = 0.5D0
      CORAZ = 0.5D0
      CORBX = 0.6D0
      CORBY = 0.6D0
      CORBZ = 0.6D0
      A = 0.509617433
      B = 7.50187547E-05
      C = 0D0
      D = 0D0
      E = 0D0
      CALL ONEODC(ODCUND,2,0,4,2,0,A,B,C,D,E,1)
      END
Comment 3 Pawel Salek 2002-09-05 08:58:39 EDT
This happens also with gcc3-g77-3.0.4-1
Comment 4 Pawel Salek 2002-09-05 10:53:04 EDT
This underflow problem *appears* to be fixed in gcc version 3.2 20020822 (Red
Hat Linux Rawhide 3.2-4)

Note You need to log in before you can comment on or make changes to this bug.