[Bug tree-optimization/111432] `bool & (a|1)` is not optimized to just `bool`
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111432 Andrew Pinski changed: What|Removed |Added Resolution|--- |FIXED Target Milestone|--- |14.0 Status|ASSIGNED|RESOLVED --- Comment #4 from Andrew Pinski --- Fixed.
[Bug tree-optimization/111432] `bool & (a|1)` is not optimized to just `bool`
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111432 --- Comment #3 from CVS Commits --- The trunk branch has been updated by Andrew Pinski : https://gcc.gnu.org/g:b18d1cabe2f90cad697e1e0bfd2abebb85f9 commit r14-4686-gb18d1cabe2f90cad697e1e0bfd2abebb85f9 Author: Andrew Pinski Date: Fri Oct 13 13:27:18 2023 -0700 MATCH: [PR111432] Simplify `a & (x | CST)` to a when we know that (a & ~CST) == 0 This adds the simplification `a & (x | CST)` to a when we know that `(a & ~CST) == 0`. In a similar fashion as `a & CST` is handle. I looked into handling `a | (x & CST)` but that I don't see any decent simplifications happening. OK? Bootstrapped and tested on x86_linux-gnu with no regressions. PR tree-optimization/111432 gcc/ChangeLog: * match.pd (`a & (x | CST)`): New pattern. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/bitops-7.c: New test.
[Bug tree-optimization/111432] `bool & (a|1)` is not optimized to just `bool`
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111432 Andrew Pinski changed: What|Removed |Added URL||https://gcc.gnu.org/piperma ||il/gcc-patches/2023-October ||/632988.html Keywords||patch --- Comment #2 from Andrew Pinski --- Patch posted: https://gcc.gnu.org/pipermail/gcc-patches/2023-October/632988.html
[Bug tree-optimization/111432] `bool & (a|1)` is not optimized to just `bool`
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111432 Andrew Pinski changed: What|Removed |Added Assignee|unassigned at gcc dot gnu.org |pinskia at gcc dot gnu.org Last reconfirmed||2023-10-10 Ever confirmed|0 |1 Status|UNCONFIRMED |ASSIGNED --- Comment #1 from Andrew Pinski --- The reason why this is correct is: a & (x | CST) -> (a & x) | (a & CST) -> // due to `a & CST -> a` (a & x) | a -> a So: ``` /* `a & (x | CST)` -> a if we know that (a & ~CST) == 0 */ (simplify (bit_and:c SSA_NAME@0 (bit_ior @1 INTEGER_CST@2)) (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) && wi::bit_and_not (get_nonzero_bits (@0), wi::to_wide (@2)) == 0) @0)) ``` // a | (x & CST) simplifies down to `(a | x) & CST` but I don't see if that is an improvement here as we still have 2 operations.