The following 3 functions should ideally generate identical code (and they do when using clang). int f1(int a, int b) { int c = b; return (a ^ b ^ c) | (a ^ b) | a; } int f2(int a, int b) { return (a ^ b) | a; } int f3(int a, int b) { return a | b; } I tested gcc revision trunk@189510 and it shows 2 missed optimizations: 1) (a ^ b ^ b) not simplified to (a) Normally gcc performs this optimization, but I *guess* it misses it here because of the CSE opportunity with (a ^ b). 2) ((a ^ b) | a) not simplified to (a | b) Of course in this example it's easy to manually rewrite the code. But in my original code this function was actually a template and for some instantiations the expression for the variable 'c' simplified to just 'b'. So the first missed optimization is something I saw in real code. The second missed optimization only occurs in this (much) simplified variant of the function.
Confirmed, f1 and f2 are the same now. So the only thing left is 2 from comment #0.
Author: prathamesh3492 Date: Thu Oct 20 07:55:28 2016 New Revision: 241360 URL: https://gcc.gnu.org/viewcvs?rev=241360&root=gcc&view=rev Log: 2016-10-20 Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org> PR tree-optimization/53979 * match.pd ((a ^ b) | a -> a | b): New pattern. testsuite/ * gcc.dg/pr53979-1.c: New test-case. * gcc.dg/pr53979-2.c: Likewise. Added: trunk/gcc/testsuite/gcc.dg/pr53979-1.c trunk/gcc/testsuite/gcc.dg/pr53979-2.c Modified: trunk/gcc/ChangeLog trunk/gcc/match.pd trunk/gcc/testsuite/ChangeLog
Can the bug be marked as resolved?
I've just checked on trunk and it looks fixed
Fixed for GCC 7.