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]

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;

}




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