🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #92

(none)

#92
From: Lee Iverson
Date: Tue, 13 Jun 1989 14:54
522 lines
11562 bytes
In the following script, the correct answers are provided without optimization.
There seems to be a serious problem with the optimization of the logic in the 
if-then-else constructs of partition().

I am running a Sun3/50 with SunOS 3.5.  We are configured with 
`config.gcc sun3'

				Lee Iverson

---- The file part.c
#include <math.h>
#include <values.h>

const double mexp = 709.782713;

double
partition( double x, double p )
{
    double nx = p*x;

    printf("In partition(%f,%f): nx = %f\n",x,p,nx);
    if ( nx <= -0.5 ) return 0.0;
    else if ( nx >= 0.5 ) return 1.0;
    else {
	double tx = 2/(2*x+1) + 2/(2*x-1);
	if ( tx <= -mexp ) return 1.0;
	else if ( tx >= mexp ) return 0.0;
	else return 1/(1+exp(tx));
    }
}

const int iterations = 1001;
const double xstart = -0.55;
const double xend   =  0.55;

main()
{
    int i;
    double x;
    const double xincr  = (xend-xstart)/(iterations-1);

    x = xstart; printf( "Part(%f) = %f\n", x, partition(x,1.0) );
    x = xend;   printf( "Part(%f) = %f\n", x, partition(x,1.0) );
    /*
    for ( i=0, x=xstart; i<iterations; ++i, x+=xincr ) {
	printf( "Part(%f) = %f\n", x, partition(x,1.0) );
    }
    */
}
---- The test run with and without optimization.

Script started on Tue Jun 13 10:14:01 1989
el[31] .../lfrl/src % gcc -v -O -c part.c; make part
gcc version 1.35
 /local/lib/gnu/gcc-cpp -v -undef -D__GNUC__ -Dmc68000 -Dsun -Dunix -D__mc68000__ -D__sun__ -D__unix__ -D__OPTIMIZE__ -D__HAVE_68881__ -Dmc68020 part.c /tmp/cca05294.cpp
GNU CPP version 1.35
 /local/lib/gnu/gcc-cc1 /tmp/cca05294.cpp -quiet -dumpbase part.c -O -version -o /tmp/cca05294.s
GNU C version 1.35 (68k, MIT syntax) compiled by GNU C version 1.35.
 /local/lib/gnu/gcc-as -mc68020 -o part.o /tmp/cca05294.s
gcc -g  part.o   -o part
el[32] .../lfrl/src % part
In partition(-0.550000,1.000000): nx = -0.550000
Part(-0.550000) = 1.000000
In partition(0.550000,1.000000): nx = 0.550000
Part(0.550000) = 0.000000
el[33] .../lfrl/src % gcc -v -c part.c; make part
gcc version 1.35
 /local/lib/gnu/gcc-cpp -v -undef -D__GNUC__ -Dmc68000 -Dsun -Dunix -D__mc68000__ -D__sun__ -D__unix__ -D__HAVE_68881__ -Dmc68020 part.c /tmp/cca05302.cpp
GNU CPP version 1.35
 /local/lib/gnu/gcc-cc1 /tmp/cca05302.cpp -quiet -dumpbase part.c -version -o /tmp/cca05302.s
GNU C version 1.35 (68k, MIT syntax) compiled by GNU C version 1.35.
 /local/lib/gnu/gcc-as -mc68020 -o part.o /tmp/cca05302.s
gcc -g  part.o   -o part
el[34] .../lfrl/src % part
In partition(-0.550000,1.000000): nx = -0.550000
Part(-0.550000) = 0.000000
In partition(0.550000,1.000000): nx = 0.550000
Part(0.550000) = 1.000000

--- The assembly code without optimization
#NO_APP
gcc_compiled.:
	.stabs "part.c",100,0,0,Ltext
Ltext:
.stabs "int:t1=r1;-2147483648;2147483647;",128,0,0,0
.stabs "char:t2=r2;0;127;",128,0,0,0
.stabs "long int:t3=r1;-2147483648;2147483647;",128,0,0,0
.stabs "unsigned int:t4=r1;0;-1;",128,0,0,0
.stabs "long unsigned int:t5=r1;0;-1;",128,0,0,0
.stabs "short int:t6=r1;-32768;32767;",128,0,0,0
.stabs "long long int:t7=r1;0;-1;",128,0,0,0
.stabs "short unsigned int:t8=r1;0;65535;",128,0,0,0
.stabs "long long unsigned int:t9=r1;0;-1;",128,0,0,0
.stabs "signed char:t10=r1;-128;127;",128,0,0,0
.stabs "unsigned char:t11=r1;0;255;",128,0,0,0
.stabs "float:t12=r1;4;0;",128,0,0,0
.stabs "double:t13=r1;8;0;",128,0,0,0
.stabs "long double:t14=r1;8;0;",128,0,0,0
.stabs "void:t15=15",128,0,0,0
.text
	.even
LC0:
	.double 0r0.00000000000000000000e+00
.stabs "mexp:G13",32,0,0,0
.globl _mexp
	.even
_mexp:
	.double 0r7.09782712999999940000e+02
LC1:
	.ascii "In partition(%f,%f): nx = %f\12\0"
	.even
LC2:
	.double 0r-5.00000000000000000000e-01
	.even
LC3:
	.double 0r5.00000000000000000000e-01
	.even
LC4:
	.double 0r1.00000000000000000000e+00
	.even
LC5:
	.double 0r2.00000000000000000000e+00
	.even
.globl _partition
_partition:
	.stabd 68,0,8
	link a6,#-24
	fmovem #0x4,sp@-
LBB2:
	.stabd 68,0,9
	fmoved a6@(16),fp2
	fmuld a6@(8),fp2
	fmoved fp2,a6@(-8)
	.stabd 68,0,11
	movel a6@(-4),sp@-
	movel a6@(-8),sp@-
	movel a6@(20),sp@-
	movel a6@(16),sp@-
	movel a6@(12),sp@-
	movel a6@(8),sp@-
	pea LC1
	jbsr _printf
	.stabd 68,0,12
	addw #28,sp
	fmoved a6@(-8),fp2
	fcmpd LC2,fp2
	fjnle L128
	movel LC0,d0
	movel LC0+4,d1
	jra L127
	jra L129
L128:
	.stabd 68,0,13
	fmoved a6@(-8),fp2
	fcmpd LC3,fp2
	fjnge L130
	movel LC4,d0
	movel LC4+4,d1
	jra L127
	jra L131
L130:
LBB3:
	.stabd 68,0,15
	fmoved LC5,fp0
	fmuld a6@(8),fp0
	faddd LC4,fp0
	fmoved LC5,fp2
	fdivx fp0,fp2
	fmovex fp2,fp0
	fmoved LC5,fp1
	fmuld a6@(8),fp1
	fsubd LC4,fp1
	fmoved LC5,fp2
	fdivx fp1,fp2
	fmovex fp2,fp1
	fmovex fp0,fp2
	faddx fp1,fp2
	fmoved fp2,a6@(-16)
	.stabd 68,0,16
	fnegd _mexp,fp0
	fcmpd a6@(-16),fp0
	fjnge L132
	movel LC4,d0
	movel LC4+4,d1
	jra L127
	jra L133
L132:
	.stabd 68,0,17
	fmoved a6@(-16),fp2
	fcmpd _mexp,fp2
	fjnge L134
	movel LC0,d0
	movel LC0+4,d1
	jra L127
	jra L135
L134:
	.stabd 68,0,18
LBB4:
	.stabs "/local/lib/gnu/gcc-include/math-68881.h",132,0,0,Ltext
	.stabd 68,0,190
	fmoved a6@(-16),fp0
	moveq #-16,d0
	addl a6,d0
LBB5:
	.stabd 68,0,194
#APP
	fetoxx fp0,fp2
#NO_APP
	fmoved fp2,a6@(-24)
	.stabd 68,0,197
	fmoved a6@(-24),fp1
	jra L136
LBE5:
	.stabd 68,0,198
L136:
LBE4:
	fmovex fp1,fp0
	faddd LC4,fp0
	fmoved LC4,fp2
	fdivx fp0,fp2
	fmoved fp2,sp@-
	movel sp@+,d0
	movel sp@+,d1
	jra L127
L135:
L133:
LBE3:
L131:
L129:
LBE2:
	.stabs "part.c",132,0,0,Ltext
	.stabd 68,0,20
L127:
	fmovem a6@(-36),#0x20
	unlk a6
	rts
.stabs "partition:F13",36,0,0,_partition
.stabs "x:p13",160,0,0,8
.stabs "p:p13",160,0,0,16
.stabs "nx:13",128,0,0,-8
.stabn 192,0,0,LBB2
.stabs "tx:13",128,0,0,-16
.stabn 192,0,0,LBB3
.stabs "x:r13",64,0,0,18
.stabn 192,0,0,LBB4
.stabs "value:13",128,0,0,-24
.stabn 192,0,0,LBB5
.stabn 224,0,0,LBE5
.stabn 224,0,0,LBE4
.stabn 224,0,0,LBE3
.stabn 224,0,0,LBE2
.stabs "iterations:G1",32,0,0,0
.globl _iterations
	.even
_iterations:
	.long 1001
.stabs "xstart:G13",32,0,0,0
.globl _xstart
	.even
_xstart:
	.double 0r-5.50000000000000040000e-01
.stabs "xend:G13",32,0,0,0
.globl _xend
	.even
_xend:
	.double 0r5.50000000000000040000e-01
LC6:
	.ascii "Part(%f) = %f\12\0"
	.even
.globl _main
_main:
	.stabd 68,0,27
	link a6,#-20
	fmovem #0x4,sp@-
LBB6:
	.stabd 68,0,30
	fmoved _xend,fp0
	fsubd _xstart,fp0
	movel _iterations,d0
	subql #1,d0
	fmovel d0,fp1
	fmovex fp0,fp2
	fdivx fp1,fp2
	fmoved fp2,a6@(-20)
	.stabd 68,0,32
	movel _xstart,a6@(-12)
	movel _xstart+4,a6@(-8)
	movel LC4+4,sp@-
	movel LC4,sp@-
	movel a6@(-8),sp@-
	movel a6@(-12),sp@-
	jbsr _partition
	movel d0,d0
	movel d1,d1
	movel d1,sp@-
	movel d0,sp@-
	movel a6@(-8),sp@-
	movel a6@(-12),sp@-
	pea LC6
	jbsr _printf
	.stabd 68,0,33
	movel _xend,a6@(-12)
	movel _xend+4,a6@(-8)
	addw #36,sp
	movel LC4+4,sp@-
	movel LC4,sp@-
	movel a6@(-8),sp@-
	movel a6@(-12),sp@-
	jbsr _partition
	movel d0,d0
	movel d1,d1
	movel d1,sp@-
	movel d0,sp@-
	movel a6@(-8),sp@-
	movel a6@(-12),sp@-
	pea LC6
	jbsr _printf
LBE6:
	.stabd 68,0,39
L137:
	fmovem a6@(-32),#0x20
	unlk a6
	rts
.stabs "main:F1",36,0,0,_main
.stabs "i:1",128,0,0,-4
.stabs "x:13",128,0,0,-12
.stabs "xincr:13",128,0,0,-20
.stabn 192,0,0,LBB6
.stabn 224,0,0,LBE6
--- The assembly code with optimization
#NO_APP
gcc_compiled.:
	.stabs "part.c",100,0,0,Ltext
Ltext:
.stabs "int:t1=r1;-2147483648;2147483647;",128,0,0,0
.stabs "char:t2=r2;0;127;",128,0,0,0
.stabs "long int:t3=r1;-2147483648;2147483647;",128,0,0,0
.stabs "unsigned int:t4=r1;0;-1;",128,0,0,0
.stabs "long unsigned int:t5=r1;0;-1;",128,0,0,0
.stabs "short int:t6=r1;-32768;32767;",128,0,0,0
.stabs "long long int:t7=r1;0;-1;",128,0,0,0
.stabs "short unsigned int:t8=r1;0;65535;",128,0,0,0
.stabs "long long unsigned int:t9=r1;0;-1;",128,0,0,0
.stabs "signed char:t10=r1;-128;127;",128,0,0,0
.stabs "unsigned char:t11=r1;0;255;",128,0,0,0
.stabs "float:t12=r1;4;0;",128,0,0,0
.stabs "double:t13=r1;8;0;",128,0,0,0
.stabs "long double:t14=r1;8;0;",128,0,0,0
.stabs "void:t15=15",128,0,0,0
.stabs "mexp:G13",32,0,0,0
.globl _mexp
.text
	.even
_mexp:
	.double 0r7.09782712999999940000e+02
LC0:
	.ascii "In partition(%f,%f): nx = %f\12\0"
	.even
.globl _partition
_partition:
	.stabd 68,0,8
	link a6,#0
	fmovem #0x1c,sp@-
	fmoved a6@(8),fp3
	fmoved a6@(16),fp0
LBB2:
	.stabd 68,0,9
	fmovex fp0,fp2
	fmulx fp3,fp2
	.stabd 68,0,11
	fmoved fp2,sp@-
	fmoved fp0,sp@-
	fmoved fp3,sp@-
	pea LC0
	jbsr _printf
	.stabd 68,0,12
	fcmpd #0r-0.5,fp2
	fjle L137
	.stabd 68,0,13
	fcmpd #0r0.5,fp2
	fjge L138
LBB3:
	.stabd 68,0,15
	fmovex fp3,fp0
	fmuld #0r2,fp0
	fmovecr #0x32,fp1
	faddx fp0,fp1
	fmoved #0r2,fp4
	fdivx fp1,fp4
	fmovex fp4,fp1
	fmovecr #0x32,fp4
	fsubx fp4,fp0
	fmoved #0r2,fp4
	fdivx fp0,fp4
	fmovex fp4,fp0
	faddx fp0,fp1
	.stabd 68,0,16
	fnegd _mexp,fp0
	fcmpx fp0,fp1
	fjnle L132
L138:
	movel #1072693248,d0
	clrl d1
	jra L127
L132:
	.stabd 68,0,17
	fcmpd _mexp,fp1
	fjnge L134
L137:
	clrl d0
	clrl d1
	jra L127
L134:
	.stabd 68,0,18
LBB4:
	.stabs "/local/lib/gnu/gcc-include/math-68881.h",132,0,0,Ltext
	.stabd 68,0,190
LBB5:
	.stabd 68,0,194
#APP
	fetoxx fp1,fp0
#NO_APP
	.stabd 68,0,197
LBE5:
	.stabd 68,0,198
LBE4:
	fmovecr #0x32,fp4
	faddx fp4,fp0
	fmovecr #0x32,fp4
	fdivx fp0,fp4
	fmoved fp4,sp@-
	movel sp@+,d0
	movel sp@+,d1
LBE3:
LBE2:
	.stabs "part.c",132,0,0,Ltext
	.stabd 68,0,20
L127:
	fmovem a6@(-36),#0x38
	unlk a6
	rts
.stabs "partition:F13",36,0,0,_partition
.stabs "x:p13",160,0,0,8
.stabs "p:p13",160,0,0,16
.stabs "x:r13",64,0,0,21
.stabs "p:r13",64,0,0,18
.stabs "nx:r13",64,0,0,20
.stabn 192,0,0,LBB2
.stabs "tx:r13",64,0,0,19
.stabn 192,0,0,LBB3
.stabn 192,0,0,LBB4
.stabs "value:r13",64,0,0,18
.stabn 192,0,0,LBB5
.stabn 224,0,0,LBE5
.stabn 224,0,0,LBE4
.stabn 224,0,0,LBE3
.stabn 224,0,0,LBE2
.stabs "iterations:G1",32,0,0,0
.globl _iterations
	.even
_iterations:
	.long 1001
.stabs "xstart:G13",32,0,0,0
.globl _xstart
	.even
_xstart:
	.double 0r-5.50000000000000040000e-01
.stabs "xend:G13",32,0,0,0
.globl _xend
	.even
_xend:
	.double 0r5.50000000000000040000e-01
LC1:
	.ascii "Part(%f) = %f\12\0"
	.even
.globl _main
_main:
	.stabd 68,0,27
	link a6,#0
	moveml #0x3030,sp@-
LBB6:
	.stabd 68,0,30
	.stabd 68,0,32
	movel _xstart,d2
	movel _xstart+4,d3
	clrl sp@-
	movel #1072693248,sp@-
	movel d3,sp@-
	movel d2,sp@-
	lea _partition,a2
	jbsr a2@
	movel d1,sp@-
	movel d0,sp@-
	movel d3,sp@-
	movel d2,sp@-
	pea LC1
	lea _printf,a3
	jbsr a3@
	.stabd 68,0,33
	movel _xend,d2
	movel _xend+4,d3
	addw #36,sp
	clrl sp@-
	movel #1072693248,sp@-
	movel d3,sp@-
	movel d2,sp@-
	jbsr a2@
	movel d1,sp@-
	movel d0,sp@-
	movel d3,sp@-
	movel d2,sp@-
	pea LC1
	jbsr a3@
LBE6:
	.stabd 68,0,39
	moveml a6@(-16),#0xc0c
	unlk a6
	rts
.stabs "main:F1",36,0,0,_main
.stabs "x:r13",64,0,0,2
.stabn 192,0,0,LBB6
.stabn 224,0,0,LBE6
Technical Details
Message-ID: <8906131454.AA05417@el.McRCIM.McGill.EDU>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!el.mcrcim.mcgill.edu!leei

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!el.mcrcim.mcgill.edu!leei
From: leei@el.mcrcim.mcgill.edu (Lee Iverson)
Newsgroups: gnu.gcc.bug
Subject: (none)
Message-ID: <8906131454.AA05417@el.McRCIM.McGill.EDU>
Date: 13 Jun 89 14:54:49 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 522