This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/53979] New: (a^b^b) not simplified to (a) (in combination with CSE??)
- From: "vermaelen.wouter at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 16 Jul 2012 10:41:16 +0000
- Subject: [Bug tree-optimization/53979] New: (a^b^b) not simplified to (a) (in combination with CSE??)
- Auto-submitted: auto-generated
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: unassigned@gcc.gnu.org
ReportedBy: vermaelen.wouter@gmail.com
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.