This is the mail archive of the gcc-patches@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]
Other format: [Raw text]

Re: [3.3] [PATCH] Do not promote integer return value...


>> The problem: Z80 port I'm working on require "char" and "int" passed
>> in the different registers (at least SDSI compiler do that). GCC
>> promotes integer types smaller than "int" to "int" without checking
>> for PROMOTE_FUNCTION_RETURN macros.
>>
>> I'm not sure which of two patches I've made should be applied to the
>> tree and if it should be rewritten in the different way (f.e., by
>> using PROMOTE_MODE or if this code need to be removed at all). Here
>> are possible patches:
>>
>> First version (removes promotion on all platforms):
>
>Do you have a test case for this?  Please supply one and tell us on
>which platforms you have tested this,

It is hard to provide a testcase because of promotion of return value
doesn't break anything. I have bootstrapped gcc with the second version
of patch under Cygwin to verify that patch is not harmful and tested it
by inspection of generated code on ip2k (the only existing target that
really affected by this change). Though I'm not familiar with ip2k CPU
it looks like the patch works properly.

The first version of proposed patch should actually eliminate extra
promotion of foo1 return value performed in function foo2 shown below
for all platforms. From the other side, I don't see any reason why
this promotion should be done at all.

Source code:
==
char foo1 (void);
char foo2 (void);

char foo1 (void)
{
  return 0x90;
}

char foo2 (void)
{
  return foo1 ();
}
==

The ip2k code before patch applied:
==
	.file	"promote-test.c"
.text
	.align 1
.global	_foo1
	.type	_foo1, @function
_foo1:
/* prologue: frame size=0 */
	push	0xfd+1
	mov	w,spl
	mov	0xfd+1,w
	mov	w,sph
	push	0xfd
	mov	0xfd,w
	mov	w,#-112
	mov	$89,w
	mov	w,#-1
	mov	$88,w
	mov	w,$88
	mov	$80,w
	mov	w,$89
	mov	$81,w
/* epilogue: frame size=0 */
	pop	0xfd
	pop	0xfd+1
	ret	
/* epilogue end (size=6) */
	.size	_foo1, .-_foo1
	.align 1
.global	_foo2
	.type	_foo2, @function
_foo2:
/* prologue: frame size=0 */
	push	calll
	push	callh
	push	0xfd+1
	mov	w,spl
	mov	0xfd+1,w
	mov	w,sph
	push	0xfd
	mov	0xfd,w
	page	_foo1
	call	_foo1
	mov	w,$81
	mov	$88,w
	mov	w,$88
	mov	$89,w
	clr	$88
	snb	wreg,7
	not	$88
	mov	w,$88
	mov	$80,w
	mov	w,$89
	mov	$81,w
/* epilogue: frame size=0 */
	pop	0xfd
	pop	0xfd+1
	pop	callh
	pop	calll
	ret	
/* epilogue end (size=10) */
	.size	_foo2, .-_foo2
	.ident	"GCC: (GNU) 3.3"
==

The ip2k code after patch applied:
==
	.file	"promote-test.c"
.text
	.align 1
.global	_foo1
	.type	_foo1, @function
_foo1:
/* prologue: frame size=0 */
	push	0xfd+1
	mov	w,spl
	mov	0xfd+1,w
	mov	w,sph
	push	0xfd
	mov	0xfd,w
	mov	w,#-112
	mov	$88,w
	mov	w,$88
	mov	$81,w
/* epilogue: frame size=0 */
	pop	0xfd
	pop	0xfd+1
	ret	
/* epilogue end (size=6) */
	.size	_foo1, .-_foo1
	.align 1
.global	_foo2
	.type	_foo2, @function
_foo2:
/* prologue: frame size=0 */
	push	calll
	push	callh
	push	0xfd+1
	mov	w,spl
	mov	0xfd+1,w
	mov	w,sph
	push	0xfd
	mov	0xfd,w
	page	_foo1
	call	_foo1
	mov	w,$81
	mov	$88,w
	mov	w,$88
	mov	$81,w
/* epilogue: frame size=0 */
	pop	0xfd
	pop	0xfd+1
	pop	callh
	pop	calll
	ret	
/* epilogue end (size=10) */
	.size	_foo2, .-_foo2
	.ident	"GCC: (GNU) 3.3"
==

-- 
Alexander Aganichev

url: http://aaganichev.narod.ru
e-mail: aaganichev@yandex.ru
gsm: +7-095-786-1339


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