https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98602
--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Naveen H.S <[email protected]>: https://gcc.gnu.org/g:729eb68a0021bd37acff6a07a505b89687b974b9 commit r17-3277-g729eb68a0021bd37acff6a07a505b89687b974b9 Author: Naveen <[email protected]> Date: Thu Aug 13 22:00:54 2026 -0700 tree-optimization: Fold canonicalized vector min/max conditionals [PR98602] The existing VEC_COND_EXPR min/max patterns require the comparison and result constants to be equal so they do not recognize this canonicalized form. Add patterns for the GE/LT forms produced from negative signed maximum expressions and for the LE/GT forms produced from positive signed or unsigned minimum expressions. Handle both normal and reversed conditional arms. The off-by-one check is performed elementwise so the transform is not restricted to uniform vector constants. This also handles non-uniform vector constants such as: X >= { -99, -98 } ? X : { -100, -99 } which can be folded to: MAX_EXPR <X, { -100, -99 }> when each comparison element is exactly one greater than the corresponding result element. Variable-length vector constants are handled when the two constants have matching VECTOR_CST encodings. gcc/ChangeLog: PR tree-optimization/98602 * match.pd (vec_cond (cmp @0 VECTOR_CST@1) @0 VECTOR_CST@2): New simplification. (vec_cond (cmp @0 VECTOR_CST@1) VECTOR_CST@2 @0): Likewise. * tree.cc (record_uniform_integer_difference): New helper. (uniform_vector_difference_p): New function. * tree.h (uniform_vector_difference_p): Declare. gcc/testsuite/ChangeLog: PR tree-optimization/98602 * g++.dg/tree-ssa/pr98602.C: New test. * g++.target/aarch64/sve/max_1.C: Remove fixed XFAILs. * g++.target/aarch64/sve/min_1.C: Likewise. Signed-off-by: Naveen <[email protected]>
