http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52254
Bug #: 52254 Summary: VRP does not fold (~a) & N to a ^ N if a has range [0, N] Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassig...@gcc.gnu.org ReportedBy: pins...@gcc.gnu.org While working on moving fold-const.c bit expression optimizations to a SSA based optimization, I found that if we optimize (a^N)&N to ~a & N, VRP does not change that to just a ^ N. Simple example: /* { dg-do compile } */ /* { dg-options "-O2 -fno-tree-ccp -fdump-tree-vrp1" } */ int f(int x) { if (x >= 0 && x <= 3) { x = (x ^ 3) & 3; } return x; } /* { dg-final { scan-tree-dump-times " & 3;" 0 "vrp1" { xfail *-*-* } } } */ /* { dg-final { cleanup-tree-dump "vrp1" } } */