On 7/22/2026 2:56 AM, Naveen wrote:
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]>
OK.    I don't see testing information, so please make sure it's been bootstrapped and regression tested before installing.

Jeff

Reply via email to