[Bug middle-end/69008] gcc emits unneeded memory access when passing trivial structs by value (ARM)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69008 Richard Biener changed: What|Removed |Added Status|NEW |ASSIGNED
[Bug middle-end/69008] gcc emits unneeded memory access when passing trivial structs by value (ARM)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69008 Philip Blundell changed: What|Removed |Added CC||pb at gcc dot gnu.org --- Comment #8 from Philip Blundell --- There seem to be a few different things going on here. With the current state of master, I no longer get the redundant ldm using the testcase from comment #7. But the store is still there: .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} sub r3, r1, #1 add sp, sp, #8 add r0, r0, r3 @ sp needed bx lr A brief inspection of the rtl suggests that the way that we wrap multiple stores in a PARALLEL might be preventing DSE from deleting the dead store. If I hack arm.md to disable the define_expand "store_multiple" then the store goes away: .LFB1: @ args = 0, pretend = 0, frame = 8 @ frame_needed = 0, uses_anonymous_args = 0 @ link register save eliminated. sub sp, sp, #8 sub r1, r1, #1 add sp, sp, #8 add r0, r0, r1 @ sp needed bx lr But we're still left with the useless stack pointer manipulation. As Andrew said in comment #4, what seems to have happened here is that we reserve a stack slot for the incoming args because they are BLKmode and, even though all the memory accesses end up being deleted, the space in the stack frame is still reserved and sp gets bumped to accommodate it. The memory references to the stack frame have been eliminated before the prologue and epilogue are generated so presumably it wouldn't be impossible to detect that the frame is no longer actually needed at this point. But I don't know how hard this would be to do in the general case.
[Bug middle-end/69008] gcc emits unneeded memory access when passing trivial structs by value (ARM)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69008 David Forgeas changed: What|Removed |Added CC||david.forgeas at gmail dot com --- Comment #7 from David Forgeas --- 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 (); } 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
[Bug middle-end/69008] gcc emits unneeded memory access when passing trivial structs by value (ARM)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69008 --- Comment #6 from Richard Earnshaw --- (In reply to Marc Mutz from comment #5) > Why is this only "missed-optimization"? Don't these architecture's ABIs > stipulate passing in registers, as well as the Itanium ABI? So why is this > not a platform ABI conformance issue? There's no conformance issue because the value is passed in registers. It's just redundantly copied onto the stack first (and then off again).
[Bug middle-end/69008] gcc emits unneeded memory access when passing trivial structs by value (ARM)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69008 Marc Mutz changed: What|Removed |Added CC||marc.mutz at kdab dot com --- Comment #5 from Marc Mutz --- Why is this only "missed-optimization"? Don't these architecture's ABIs stipulate passing in registers, as well as the Itanium ABI? So why is this not a platform ABI conformance issue?
[Bug middle-end/69008] gcc emits unneeded memory access when passing trivial structs by value (ARM)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69008 Andrew Pinski changed: What|Removed |Added Component|rtl-optimization|middle-end --- Comment #4 from Andrew Pinski --- I know there are other bug reports about this exact same thing. One for PowerPC but I can't seem to find it. I thought I had filed it but it looks like someone else did. >From what I remember Trivial is given BLKmode so it always go to the stack even though the it is passed via two registers.