[Bug c++/85720] New: bad codegen for looped assignment of primitives at -O2
redbeard0531 at gmail dot com
gcc-bugzilla@gcc.gnu.org
Wed May 9 18:37:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85720
Bug ID: 85720
Summary: bad codegen for looped assignment of primitives at -O2
Product: gcc
Version: 8.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: redbeard0531 at gmail dot com
Target Milestone: ---
https://godbolt.org/g/qp19Cv
using SIZE_T = decltype(sizeof(0));
void fill(char* p, SIZE_T n) {
for (SIZE_T i = 0; i < n; i++){
p[i] = -1;
}
}
fill(char*, unsigned long):
test rsi, rsi
je .L1
add rsi, rdi
.L3:
mov BYTE PTR [rdi], -1
add rdi, 1
cmp rdi, rsi
jne .L3
.L1:
ret
At -O3 it basically just tail-calls memset.
Also applies to other types than char, but char is most egregious.
This ticket is spun out of from
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85707
More information about the Gcc-bugs
mailing list