https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109878
--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Andrew Pinski <[email protected]>: https://gcc.gnu.org/g:a20efc87806dd0f9f75a69a65547cce0e5e13e5b commit r17-395-ga20efc87806dd0f9f75a69a65547cce0e5e13e5b Author: Eikansh Gupta <[email protected]> Date: Wed May 6 18:08:45 2026 +0530 MATCH: Add simplification for MAX<a&CST0,a&CST1> and MIN<a&CST0,a&CST1> to match.pd [PR109878] Min and max could be optimized if both operands are defined by (same) variable restricted by an and(&). For signed types, optimization can be done when both constant have same sign bit. The patch also adds optimization for specific case of min/max(a, a&CST). This patch adds match pattern for: max (a & CST0, a & CST1) -> a & CST0 IFF CST0 & CST1 == CST1 min (a & CST0, a & CST1) -> a & CST0 IFF CST0 & CST1 == CST0 min (a, a & CST) --> a & CST max (a, a & CST) --> a The v2 of the patch has been approved. Patch link: https://gcc.gnu.org/pipermail/gcc-patches/2024-July/657801.html PR tree-optimization/109878 gcc/ChangeLog: * match.pd(min/max (a & CST0, a & CST1)): New pattern. (min/max (a, a & CST)): New pattern. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr109878-1.c: New test. * gcc.dg/tree-ssa/pr109878-2.c: New test. * gcc.dg/tree-ssa/pr109878-3.c: New test. * gcc.dg/tree-ssa/pr109878.c: New test. Signed-off-by: Eikansh Gupta <[email protected]>
