🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #1048

Gcc 2.1 produces not really optimized code when using -fcse-follow-jumps

#1048
From: Linus Tolke Y
Date: Wed, 02 Sep 1992 23:29
87 lines
3878 bytes
I am running gcc version 2.1 on a SunOS 4.1.1 system with sun3s and a
sun4 server.

While testing how the code from the tail-recursion looked like I came
across the following strange behaviour.

My infile is:
rek.c  =========================================================
unsigned int zero(unsigned int a) {
    if (a > 0) 
	return zero(a-1);
    else
	return a;
}
================================================================
I compile it with the -S to get the assembly code and the -O or the
 -O -fcse-follow-jumps.

This is what happens on a Sun4 running SunOS Release 4.1.1:

% gcc -O -S rek.c
% mv rek.s rek-O.s
% gcc -O -fcse-follow-jumps -S rek.c
% mv rek.s rek-O-fcse-follow-jumps.s
% sdiff -w70 rek-O.s rek-O-fcse-follow-jumps.s
gcc2_compiled.:                      gcc2_compiled.:
.text                                .text
	.align 4                     	.align 4
	.global _zero                	.global _zero
	.proc 1                      	.proc 1
_zero:                               _zero:
	!#PROLOGUE# 0                	!#PROLOGUE# 0
	save %sp,-112,%sp            	save %sp,-112,%sp
	!#PROLOGUE# 1                	!#PROLOGUE# 1
L3:                                  L3:
	cmp %i0,0                    	cmp %i0,0
	be L2                        	be L2
	nop                          	nop
	b L3                         	b L3
	add %i0,-1,%i0               	add %i0,-1,%i0
L2:                                  L2:
	ret                          	ret
	restore                   |  	restore %g0,0,%o0
% 
================================================================
This is what happens on a Sun3 running SunOS Release 4.1.1:

% gcc -O -S rek.c
% mv rek.s rek-O.s
% gcc -O -fcse-follow-jumps -S rek.c
% mv rek.s rek-O-fcse-follow-jumps.s
% sdiff -w70 rek-O.s rek-O-fcse-follow-jumps.s
#NO_APP                              #NO_APP
gcc2_compiled.:                      gcc2_compiled.:
.text                                .text
        .even                           .even
.globl _zero                         .globl _zero
_zero:                               _zero:
        link a6,#0                      link a6,#0
        movel a6@(8),d0                 movel a6@(8),d0
L3:                                  L3:
        tstl d0                         tstl d0
        jeq L2                          jeq L2
        subql #1,d0                     subql #1,d0
        jra L3                          jra L3
L2:                                  L2:
                                  >     clrl d0
        unlk a6                         unlk a6
        rts                             rts
% 
================================================================
The -fcse-follow-jumps seems to create excessive code in some respect.

Yes: I have not tested if this behaviour is present in gcc 2.2.2
(noone has had time to compile it here yet) but I have glanced through
the diffs of the ChangeLog and I did not find anything that I could
connect to this behaviour being fixed.

Brag: I noticed it first while comparing a -O compiled program with a
-O4 compiled program but managed to narrow it down to the
-fcse-follow-jumps flag.
-- 
	/Linus
*****	Wherever I exec my `which emacs`, is my $HOME.	*****
Linus Tolke				SM7OUU, linus@lysator.liu.se
Student at the				member of SK5EU LiTHSA
Link|ping institute of technology, LiTH	LiTH S{ndare Amat|rer (Ham-club)
Technical Details
Message-ID: <199209021929.AA23323@lysator.liu.se>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!lysator.liu.se!linus

Show Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!lysator.liu.se!linus
From: linus@lysator.liu.se (Linus Tolke Y)
Subject: Gcc 2.1 produces not really optimized code when using -fcse-follow-jumps
Message-ID: <199209021929.AA23323@lysator.liu.se>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Wed, 2 Sep 1992 23:29:45 GMT
Approved: bug-gcc@prep.ai.mit.edu
Lines: 88