[Bug middle-end/98710] missing optimization (x | c) & ~(y | c) -> x & ~(y | c)
pinskia at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Sun Sep 3 20:22:22 GMT 2023
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98710
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=103536
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
```
unsigned foo(unsigned x, unsigned y, unsigned c)
{
return (x | c) & ~(y | c); // x & ~(y | c);
}
unsigned foo_or(unsigned x, unsigned y, unsigned c)
{
return (x & c) | ~(y & c); // x | ~(y & c);
}
unsigned foo2(unsigned x, unsigned y, unsigned c)
{
return x & ~(y | x); // 0
}
unsigned foo2_or(unsigned x, unsigned y, unsigned c)
{
return x | ~(y & x); // -1
}
```
// (x | c) & ~(y | c) -> x & ~(y | c)
// (x & c) | ~(y & c) -> x | ~(y & c)
(for bitop (bit_and bit_ior)
rbitop (bit_ior bit_and)
(bitop:c (rbitop:c @0 @1) (bit_not@3 (rbitop:c @1 @2)))
(bitop @0 @3))
// x & ~(y | x) -> 0
// x | ~(y & x) -> -1
(for bitop (bit_and bit_ior)
rbitop (bit_ior bit_and)
(bitop:c @0 (bit_not (rbitop:c @0 @1)))
(if (bitop == BIT_AND_EXPR)
{ build_zero_cst (type); }
{ build_minus_one_cst (type); }))
More information about the Gcc-bugs
mailing list