https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72795
Peter Cordes <peter at cordes dot ca> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |peter at cordes dot ca --- Comment #1 from Peter Cordes <peter at cordes dot ca> --- This is not a bug. Adding int gety(){ return y; } to the compilation unit leads to the same asm for f() and g(). (https://godbolt.org/g/4z94YZ). It can only be optimized away when there are no observers. f() and g() have side-effects on global / static variables which of course can't be optimized away. BTW, this came up based on http://stackoverflow.com/a/38741832/224132.