This is the mail archive of the gcc@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: Why are these two functions compiled differently?


Should I file a bug report? If it is not a C semantics thing, GCC certainly produces unnecessarily big code. 

	.file	"tst.c"
	.text
	.p2align 4,,15
.globl tst1
	.type	tst1, @function
tst1:
.LFB0:
	.cfi_startproc
	movswl	%si,%esi
	movswl	%di,%edi
	xorl	%eax, %eax
	subl	$254, %esi
	cmpl	%edi, %esi
	setg	%al
	ret
	.cfi_endproc
.LFE0:
	.size	tst1, .-tst1
	.p2align 4,,15
.globl tst2
	.type	tst2, @function
tst2:
.LFB1:
	.cfi_startproc
	subw	$255, %si
	xorl	%eax, %eax
	cmpw	%di, %si
	setge	%al
	ret
	.cfi_endproc
.LFE1:
	.size	tst2, .-tst2
	.ident	"GCC: (GNU) 4.4.0 20090218 (experimental) [trunk revision 143368]"
	.section	.note.GNU-stack,"",@progbits

> -----Original Message-----
> From: Richard Guenther [mailto:richard.guenther@gmail.com] 
> Sent: 03 March 2009 15:16
> To: Bingfeng Mei
> Cc: gcc@gcc.gnu.org; John Redford
> Subject: Re: Why are these two functions compiled differently?
> 
> On Tue, Mar 3, 2009 at 4:06 PM, Bingfeng Mei 
> <bmei@broadcom.com> wrote:
> > Hello,
> > I came across the following example and their 
> .final_cleanup files. To me, both functions should produce 
> the same code. But tst1 function actually requires two extra 
> sign_extend instructions compared with tst2. Is this a C 
> semantics thing, or GCC mis-compile (over-conservatively) in 
> the first case.
> 
> Both transformations are already done by the fronted (or fold), likely
> shorten_compare is quilty for tst1 and fold_unary for tst2 (which
> folds (short)((int)b - (int)A).
> 
> Richard.
> 
> > Cheers,
> > Bingfeng Mei
> > Broadcom UK
> >
> >
> > #define A ?255
> >
> > int tst1(short a, short b){
> > ?if(a > (b - A))
> > ? ?return 0;
> > ?else
> > ? ?return 1;
> >
> > }
> >
> >
> > int tst2(short a, short b){
> > ?short c = b - A;
> > ?if(a > c)
> > ? ?return 0;
> > ?else
> > ? ?return 1;
> >
> > }
> >
> >
> > .final_cleanup
> > ;; Function tst1 (tst1)
> >
> > tst1 (short int a, short int b)
> > {
> > <bb 2>:
> > ?return (int) b + -254 > (int) a;
> >
> > }
> >
> >
> >
> > ;; Function tst2 (tst2)
> >
> > tst2 (short int a, short int b)
> > {
> > <bb 2>:
> > ?return (short int) ((short unsigned int) b + 65281) >= a;
> >
> > }
> >
> >
> >
> >
> 
> 


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