🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #53388

constants

#53388
From: meissner
Date: Fri, 10 Jan 1992 06:28
109 lines
3156 bytes
| Hello,
| 	Most of the RISC architectures have a limited number
| 	bits in the field holding immediat operand. When the
| 	constant is too wide, it is not possible to use this
| 	field; so the compiler has to generate few instruc-
| 	tions (2 on a 32-bit machine) to load the constant 
| 	into a register.
| 	The problem with gcc is that transformation of an
| 	immediat operand into a register load is performed
| 	by the last pass (instruction selection). If this
| 	transformation takes place inside a loop, the load 
| 	could be move outside of the loop, but because the
| 	strength-reduction optimization has already been
| 	done, it is too late for that.
| 	----------------------------------------------------
| 		foo(int a[], int b[], int n)
| 		{
| 			int i;
| 
| 			for (i = 0; i < n; i++)
| 			{
| 				a[i] = b[i] + 5000;
| 			}
| 		}
| 	----------------------------------------------------

| 	So, is anybody is able to suggest a way to do the
| 	same with gcc, I will be pleased to know it.  Thanx.

Umm, I suspect this is a SPARC specific bug, rather than a general GCC
bug.  I have found in general, it is best to have the recognizer
functions (the gen_xxx functions) be close to the machine, though
there are cases where it's better to lie a little, and pretend the
machine is more general.

Here is what the 1.39 version of the MIPS compiler generates (I
had to change the 5000 to 50000, since the MIPS allows 16 bit signed
constants), with delayed branches turned off to improve the clarity:

		.file	1 "foo.c"
		.data

	gcc_compiled.:
		.text
		.align	2
		.globl	foo

		.loc	1 2
		.ent	foo
	foo:
		.frame	$sp,0,$31
		.mask	0x00000000,0
		.fmask	0x00000000,0
		move	$7,$5
		move	$5,$6
		move	$2,$0
		bge	$2,$5,$L6
		li	$6,500000
		move	$3,$7
		sll	$2,$5,2
		addu	$5,$2,$7
	$L5:
		lw	$2,0($3)
		addu	$2,$2,$6
		sw	$2,0($4)
		addu	$3,$3,4
		addu	$4,$4,4
		blt	$3,$5,$L5
	$L6:
		j	$31
		.end	foo

Here is the same code with the 2.00 compiler:

		.file	1 "foo.c"
		.data

	gcc2_compiled.:
		.text
		.align	2
		.globl	foo

		.loc	1 2
		.ent	foo
	foo:
		.frame	$sp,0,$31
		.mask	0x00000000,0
		.fmask	0x00000000,0
		move	$3,$0
		bge	$3,$6,$L3
		lui	$7,(0x00070000)>>16
		ori	$7,$7,0xa120
	$L5:
		lw	$2,0($5)
		addu	$5,$5,4
		addu	$3,$3,1
		addu	$2,$2,$7
		sw	$2,0($4)
		addu	$4,$4,4
		blt	$3,$6,$L5
	$L3:
		j	$31
		.end	foo

--
Michael Meissner	email: meissner@osf.org		phone: 617-621-8861
Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142

You are in a twisty little passage of standards, all conflicting.
Technical Details
Message-ID: <9201101628.AA14225@curley.osf.org>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!osf.ORG!meissner
References: meissner@osf.ORG

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,a4e58e06910fc6e8
X-Google-Attributes: gid11318c,public
X-Google-ArrivalTime: 1992-01-10 08:51:23 PST
Newsgroups: gnu.gcc.help
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!osf.ORG!meissner
From: meissner@osf.ORG
Subject: constants
Message-ID: <9201101628.AA14225@curley.osf.org>
Sender: daemon@cis.ohio-state.edu
Organization: GNUs Not Usenet
References: meissner@osf.ORG
Distribution: gnu
Date: Fri, 10 Jan 1992 06:28:15 GMT
Lines: 109