[Bug middle-end/88387] New: Possible code optimization when right shift count >= width of type
bugzilla@poradnik-webmastera.com
gcc-bugzilla@gcc.gnu.org
Thu Dec 6 11:06:00 GMT 2018
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]
More information about the Gcc-bugs
mailing list