http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53979
Bug #: 53979
Summary: (a^b^b) not simplified to (a) (in combination with
CSE??)
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: tree-optimization
AssignedTo: [email protected]
ReportedBy: [email protected]
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.