[Bug rtl-optimization/94026] combine missed opportunity to simplify comparisons with zero

felix.yang at huawei dot com gcc-bugzilla@gcc.gnu.org
Mon Mar 16 03:34:22 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94026

--- Comment #4 from Fei Yang <felix.yang at huawei dot com> ---
(In reply to Fei Yang from comment #0)
> Created attachment 47966 [details]
> proposed patch to fix this issue
> 
> Simple test case:
> int
> foo (int c, int d)
> {
>   int a = (c >> d) & 7;
> 
>   if (a >= 2) {
>     return 1;
>   }
> 
>   return 0;
> }
> 
> Compile option: gcc -S -O2 test.c
> 
> 
> On aarch64, GCC trunk emits 4 instrunctions:
>         asr     w0, w0, 8
>         tst     w0, 6
>         cset    w0, ne
>         ret
> 
> which can be further simplified into:
>         tst     x0, 1536
>         cset    w0, ne
>         ret
> 
> We see the same issue on other targets such as i386 and x86-64.
> 
> Attached please find proposed patch for this issue.

The previously posted test case is not correct.
Test case should be:
int fifth (int c)
{
    int a = (c >> 8) & 7;

    if (a >= 2) {
        return 1;
    } else {
        return 0;
    }
}


More information about the Gcc-bugs mailing list