This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/88387] New: Possible code optimization when right shift count >= width of type
- From: "bugzilla at poradnik-webmastera dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 06 Dec 2018 11:06:25 +0000
- Subject: [Bug middle-end/88387] New: Possible code optimization when right shift count >= width of type
- Auto-submitted: auto-generated
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]