I know the title is a bit confusing. Let me clarify my problem with a little background:
My program behaves strangely when I compile it with -O1
flag vs
The optimizations flags applied by -O1
only apply when the optimizer is turned on. You need to specify -On
with n > 0
in order for the optimization flags to actually do anything.
To put it another way, -O0
doesn't turn on the optimizer, so the optimization flags don't do anything.
You can turn off optimzations flags by using the -fno
form of the flag. For instance the
-fcompare-elim
flag is turned on by -O1
and you can turn it back off using
-fno-compare-elim
Another thing to note, as pointed out by T.C., is that not all optimizations have a flag so there isn't any way to turn those particular optimizations off.