From gcc5.4 documentation, it says
-O2 turns on all optimization flags specified by -O. It also turns on the following optimization flags: -ft
-O2 turns on all optimization flags specified by -O. It also turns on the following optimization flags:
-ft
It is a common gotcha. In order to enable (or disable) specific optimizations, you must first enable the optimizer in general, i.e. use one of -O... flags, except -O0 (or just -O, which is equivalent to -O1).
-O...
-O0
-O
-O1