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?


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]