This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/82187] New: missing optimization pointer to char*
- From: "loader2x at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 12 Sep 2017 08:11:53 +0000
- Subject: [Bug c/82187] New: missing optimization pointer to char*
- Auto-submitted: auto-generated
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.