This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Why are these two functions compiled differently?
- From: "Bingfeng Mei" <bmei at broadcom dot com>
- To: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Cc: "John Redford" <jredford at broadcom dot com>
- Date: Tue, 3 Mar 2009 07:06:57 -0800
- Subject: Why are these two functions compiled differently?
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.
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;
}