https://gcc.gnu.org/g:d1b4bf7c25ca1a57bb438b91439c0484eb73ac64
commit r17-4490-gd1b4bf7c25ca1a57bb438b91439c0484eb73ac64 Author: Andrea Pinski <[email protected]> Date: Sat Sep 19 14:57:03 2026 -0700 match: Remove comparison check for a vec_cond pattern This pattern is currently: `((VCE (a cmp b ? -1 : 0)) < 0) ? c : d` But the inner comparison does not matter for VEC_COND so let's remove it to reduce generated code from genmatch. It might also optimize things that used `a & b` rather than a comparison. Though in the original case does not matter. Note this pattern can be simplified more but I am not handling that right now. Bootstrapped and tested on x86_64-linux-gnu. gcc/ChangeLog: * match.pd (`((VCE (a cmp b ? -1 : 0)) < 0) ? c : d`): Remove `(a cmp b)` match part. Signed-off-by: Andrea Pinski <[email protected]> Diff: --- gcc/match.pd | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index 0e96727083f7..341962a3faac 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -6850,27 +6850,23 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (optimize_vectors_before_lowering_p () && types_match (@0, @3)) (vec_cond (bit_and @0 (bit_not @3)) @2 @1))) -/* ((VCE (a cmp b ? -1 : 0)) < 0) ? c : d is just - (VCE ((a cmp b) ? (VCE c) : (VCE d))) when TYPE_PRECISION of the +/* ((VCE (a ? -1 : 0)) < 0) ? c : d is just + (VCE (a ? (VCE c) : (VCE d))) when TYPE_PRECISION of the component type of the outer vec_cond is greater equal the inner one. */ -(for cmp (simple_comparison) - (simplify - (vec_cond - (lt (view_convert@5 (vec_cond@6 (cmp@4 @0 @1) - integer_all_onesp - integer_zerop)) - integer_zerop) @2 @3) - (if (VECTOR_INTEGER_TYPE_P (TREE_TYPE (@0)) - && VECTOR_INTEGER_TYPE_P (TREE_TYPE (@5)) - && !TYPE_UNSIGNED (TREE_TYPE (@5)) - && VECTOR_TYPE_P (TREE_TYPE (@6)) - && VECTOR_TYPE_P (type) - && tree_int_cst_le (TYPE_SIZE (TREE_TYPE (type)), - TYPE_SIZE (TREE_TYPE (TREE_TYPE (@6)))) - && TYPE_SIZE (type) == TYPE_SIZE (TREE_TYPE (@6))) - (with { tree vtype = TREE_TYPE (@6);} - (view_convert:type - (vec_cond @4 (view_convert:vtype @2) (view_convert:vtype @3))))))) +(simplify + (vec_cond + (lt (view_convert@5 (vec_cond@6 @4 integer_all_onesp integer_zerop)) + integer_zerop) @2 @3) + (if (VECTOR_INTEGER_TYPE_P (TREE_TYPE (@5)) + && !TYPE_UNSIGNED (TREE_TYPE (@5)) + && VECTOR_TYPE_P (TREE_TYPE (@6)) + && VECTOR_TYPE_P (type) + && tree_int_cst_le (TYPE_SIZE (TREE_TYPE (type)), + TYPE_SIZE (TREE_TYPE (TREE_TYPE (@6)))) + && TYPE_SIZE (type) == TYPE_SIZE (TREE_TYPE (@6))) + (with { tree vtype = TREE_TYPE (@6);} + (view_convert:type + (vec_cond @4 (view_convert:vtype @2) (view_convert:vtype @3)))))) /* c1 ? c2 ? a : b : b --> (c1 & c2) ? a : b */ (simplify
