[Bug middle-end/69008] gcc emits unneeded memory access when passing trivial structs by value (ARM)
david.forgeas at gmail dot com
gcc-bugzilla@gcc.gnu.org
Sat Mar 21 22:36:30 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69008
David Forgeas <david.forgeas at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |david.forgeas at gmail dot com
--- Comment #7 from David Forgeas <david.forgeas at gmail dot com> ---
The use case that made me see this is std::string_view, or equivalently:
namespace my {
struct string_view {
const char *data;
unsigned long length;
const char & back() const {
return data[length - 1];
}
};
}
const char *back(my::string_view const sv)
{
return &sv.back();
}
pi@raspberrypi:~ $ g++ -O3 -pipe -S string_view.cpp -std=c++1z
pi@raspberrypi:~ $ cat string_view.s
.arch armv6
.eabi_attribute 28, 1
.eabi_attribute 20, 1
.eabi_attribute 21, 1
.eabi_attribute 23, 3
.eabi_attribute 24, 1
.eabi_attribute 25, 1
.eabi_attribute 26, 2
.eabi_attribute 30, 2
.eabi_attribute 34, 1
.eabi_attribute 18, 4
.file "string_view.cpp"
.text
.align 2
.global _Z4backN2my11string_viewE
.syntax unified
.arm
.fpu vfp
.type _Z4backN2my11string_viewE, %function
_Z4backN2my11string_viewE:
.fnstart
.LFB1:
@ args = 0, pretend = 0, frame = 8
@ frame_needed = 0, uses_anonymous_args = 0
@ link register save eliminated.
sub sp, sp, #8
add r3, sp, #8
stmdb r3, {r0, r1}
ldm sp, {r0, r3}
sub r3, r3, #1
add r0, r0, r3
add sp, sp, #8
@ sp needed
bx lr
.cantunwind
.fnend
.size _Z4backN2my11string_viewE, .-_Z4backN2my11string_viewE
.ident "GCC: (Raspbian 6.3.0-18+rpi1+deb9u1) 6.3.0 20170516"
Also seen in a more recent version: https://godbolt.org/z/3LJ9SN
More information about the Gcc-bugs
mailing list