This is the mail archive of the gcc-bugs@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]

[Bug middle-end/88387] New: Possible code optimization when right shift count >= width of type


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

            Bug ID: 88387
           Summary: Possible code optimization when right shift count >=
                    width of type
           Product: gcc
           Version: 8.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bugzilla@poradnik-webmastera.com
  Target Milestone: ---

When signed int is shifted right by more than its width, results will be either
0 or -1. This can used to simplify conditions like in test() to sign check as
in test2(). Example code below was compiled using gcc 8.2 with -O3
-march=skylake-avx512.

[code]
void f();
void g();

void test(int n)
{
    if (n >> 2222)
        f();
    else
        g();
}

void test2(int n)
{
    if (n < 0)
        f();
    else
        g();
}
[/code]

[asm]
test(int):
        mov     eax, -82
        sarx    edi, edi, eax
        test    edi, edi
        je      .L2
        jmp     f()
.L2:
        jmp     g()
test2(int):
        test    edi, edi
        js      .L6
        jmp     g()
.L6:
        jmp     f()
[/code]

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