https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88271
Bug ID: 88271
Summary: Omit test instruction after add
Product: gcc
Version: 8.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: [email protected]
Target Milestone: ---
[code]
int data[8];
void test(int k)
{
int level = 0;
int val = 1;
while (1)
{
if (val)
{
val = data[level] << 1;
++level;
}
else
{
--level;
val = data[level];
}
}
}
[/code]
This code compiled using gcc 8.2 with options -O3 -march=skylake-avx512
produces this:
[asm]
test(int):
mov edx, 1
xor eax, eax
.L2:
test edx, edx
je .L3
.L6:
movsx rdx, eax
mov edx, DWORD PTR data[0+rdx*4]
inc eax
add edx, edx
test edx, edx
jne .L6
.L3:
dec eax
movsx rdx, eax
mov edx, DWORD PTR data[0+rdx*4]
jmp .L2
data:
.zero 32
[/asm]
I checked that add instruction updates CPU flags, so test instruction before
"jne .L6" could be omitted.