https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87186
--- Comment #4 from MCCCS <mcccs at gmx dot com> --- Flags: -O2 -fdump-tree-original Code: int f1 (int x, int s) { return ~(~(x|s)|x)|~(~(x|s)|s); } int f2 (int x, int s) { const int t = x|s; return ~(~t|x)|~(~t|s); } int f3 (int x, int s) { const int t = ~(x|s); return ~(t|x)|~(t|s); } int f4 (int x, int s) { const int t = ~x&~s; return ~(t|x)|~(t|s); } Tree output (f1 has the expected output, others should have had the same output): ;; Function f1 (null) ;; enabled by -tree-original { return s ^ x; } ;; Function f2 (null) ;; enabled by -tree-original { const int t = x | s; const int t = x | s; return ~((int) ~t | x & s); } ;; Function f3 (null) ;; enabled by -tree-original { const int t = ~(x | s); const int t = ~(x | s); return ~(x & s | (int) t); } ;; Function f4 (null) ;; enabled by -tree-original { const int t = ~(x | s); const int t = ~(x | s); return ~(x & s | (int) t); }