I went through all the optimisations that are in -O2 but not -O1 (-falign-functions -falign-jumps -falign-labels -fcaller-saves -fcrossjumping -fcse-follow-jumps -fdelete-null-pointer-checks -fexpensive-optimizations -fforward-propagate -fgcse -finline-small-functions -fipa-cp -foptimize-register-move -foptimize-sibling-calls -fpeephole2 -fregmove -freorder-blocks -freorder-functions -frerun-cse-after-loop -fschedule-insns2 -fstrict-aliasing -fthread-jumps -ftree-builtin-call-dce -ftree-pre -ftree-switch-conversion -ftree-vrp). Not a single one of them produces this effect reliably, but the bulk of them produce it sometimes.
I went through all the optimisations that are in -O2 but not -O1 (-falign-functions -falign-jumps -falign-labels -fcaller-saves -fcrossjumping -fcse-follow-jumps -fdelete- null-pointer- checks -fexpensive- optimizations -fforward-propagate -fgcse -finline- small-functions -fipa-cp -foptimize- register- move -foptimize- sibling- calls -fpeephole2 -fregmove -freorder-blocks -freorder-functions -frerun- cse-after- loop -fschedule-insns2 -fstrict-aliasing -fthread-jumps -ftree- builtin- call-dce -ftree-pre -ftree- switch- conversion -ftree-vrp). Not a single one of them produces this effect reliably, but the bulk of them produce it sometimes.