[Bug tree-optimization/98602] Failure to optimise vector “x > -100 ? x : -100” to MAX_EXPR
cvs-commit at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Aug 14 05:01:50 GMT 2026
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 <naveenh@gcc.gnu.org>:
https://gcc.gnu.org/g:729eb68a0021bd37acff6a07a505b89687b974b9
commit r17-3277-g729eb68a0021bd37acff6a07a505b89687b974b9
Author: Naveen <naveen.siddegowda@oss.qualcomm.com>
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 <naveen.siddegowda@oss.qualcomm.com>
More information about the Gcc-bugs
mailing list