[Bug tree-optimization/106138] Inefficient code generation: logical AND of disjoint booleans from equal and bitwise AND not optimized to constant false
pinskia at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Jul 7 20:39:51 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106138
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
Last reconfirmed| |2022-07-07
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #2)
> I'd say reassoc would be a better place to handle it, so that we handle both
> the logical op short circuit && and x == 4 && y == 25 && z != 16 && (x & 3)
> != 0.
Right now reassoc calls maybe_fold_and_comparisons and
maybe_fold_or_comparisons which are places where this could be added. Or even
match-and-simplify gets called (via those two functions).
You could add it either in combine_comparisons or match.pd.
Maybe something like (psedu code as I didn't add the wi part and it can be
extended and all):
(simplify
(bit_and
(eq @0 INTEGER_CST@1)
(ne (bit_and @0 INTEGER_CST@2) zero_p))
(if ((@1 & @2) == 0))
({true_bool_value;}))
You can change @1 and @2 to
with_possible_nonzero_bits/with_possible_nonzero_bits2 and then compare the
nonzero bits to see if they overlap.
Also extend it to handle ior too.
More information about the Gcc-bugs
mailing list