[Bug c/82187] New: missing optimization pointer to char*
loader2x at gmail dot com
gcc-bugzilla@gcc.gnu.org
Tue Sep 12 08:13:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82187
Bug ID: 82187
Summary: missing optimization pointer to char*
Product: gcc
Version: 7.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: loader2x at gmail dot com
Target Milestone: ---
I have this code: main.c:
int main(int c, char **v){
char *s = v[0];
while (*s++ != 0) {
if ((*s == 'a') && (*s != 'b')) {
return 1;
}
}
return 0;
}
which I compile generating the assembly code:
gcc -S -masm=intel -O3 main.c
main:
.LFB0:
.cfi_startproc
mov rax, QWORD PTR [rsi]
jmp .L2
.p2align 4,,10
.p2align 3
.L4:
cmp BYTE PTR [rax], 97
je .L5
.L2:
add rax, 1
cmp BYTE PTR -1[rax], 0
jne .L4
xor eax, eax
ret
.L5:
mov eax, 1
ret
There are two accesses to the memory, it could be optimized to one access to
the memory.
When I set 'volatile char *s = v[0];', there are 3 accesses to the memory which
is good.
More information about the Gcc-bugs
mailing list