3 ms·
-O2 will remove stack pointer setup
by rasz_pl 10y ago
-O2 will remove stack pointer setup
- Annatar 10y agoYou have to have stack and frame setup if the code is to be ABI / target platform's calling convention compliant. Which compiler are you referring to, because GCC won't remove it, as far as I could tell looking at the generated assembler code? You could purposely tell GCC to omit the frame pointer -fomit-frame-pointer, but then you just made the code extremely difficult to debug (and stack setup code will still be generated, as the compiler can't generate useful / functional code without it), so that's no solution either.
- rasz_pl 10y agoyou dont need to setup local stack if your code doesnt use stack
- Annatar 10y agoPlease provide instructions on how to reproduce / verify the assertion that GCC doesn't generate stack / frame pointer setup. I want to see this for myself.
- olegolegovich 10y agoThe x86-64 ABI does not require frame pointer setup: https://godbolt.org/g/10URYW https://godbolt.org/g/10URYW
- Annatar 10y agoThat's a contrived example of inlining; now watch what happens when you provide more than just a trivial function which can be inlined; look at all the futzing it does with the stack: https://godbolt.org/g/tjrKNO https://godbolt.org/g/tjrKNO without explicit direction from humans, compilers can't generate code which calls subroutines or functions without using the stack at the very minimum, and that was my point. And that's just GCC on intel; check out intel's compiler, it's even worse (click on "turn off intel syntax", and "compile to binary and disassemble the output"): https://godbolt.org/g/IjGdAP https://godbolt.org/g/IjGdAP ...and if you try other processors as well, it just gets worse and worse: https://godbolt.org/g/DZDLju https://godbolt.org/g/DZDLju https://godbolt.org/g/s47tlR https://godbolt.org/g/s47tlR