From 2a39c42a42cdea4a8962b9e140b88e0051894f38 Mon Sep 17 00:00:00 2001 From: Kewen Lin Date: Wed, 8 Jul 2020 22:27:41 -0500 Subject: [PATCH] vect: Enhance condition check to use partial vectors This patch is derived from the review of vector with length patch series. The length-based partial vector approach doesn't support reduction so far, so we would like to disable vectorization with partial vectors explicitly for it in vectorizable_condition. Otherwise, it will cause some unexpected failures for a few cases like gcc.dg/vect/pr65947-2.c. But if we disable it for the cases excepting for reduction_type equal to EXTRACT_LAST_REDUCTION, it cause one regression failure on aarch64: gcc.target/aarch64/sve/reduc_8.c -march=armv8.2-a+sve The disabling makes the outer loop can't work with partial vectors, the check fails. But the case is safe to adopt it. As Richard S. pointed out in the review comments, the extra inactive lanes only matter for double reductions, so this patch is to permit vectorization with partial vectors for cases EXTRACT_LAST_REDUCTION or nested-cycle reduction. Bootstrapped/regtested on aarch64-linux-gnu. gcc/ChangeLog: * tree-vect-stmts.c (vectorizable_condition): Prohibit vectorization with partial vectors explicitly excepting for EXTRACT_LAST_REDUCTION or nested-cycle reduction. --- gcc/tree-vect-stmts.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c index cec5c601268..5eae74e8042 100644 --- a/gcc/tree-vect-stmts.c +++ b/gcc/tree-vect-stmts.c @@ -9876,11 +9876,22 @@ vectorizable_condition (vec_info *vinfo, return false; } - if (loop_vinfo - && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) - && reduction_type == EXTRACT_LAST_REDUCTION) - vect_record_loop_mask (loop_vinfo, &LOOP_VINFO_MASKS (loop_vinfo), - ncopies * vec_num, vectype, NULL); + if (loop_vinfo && for_reduction + && LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo)) + { + if (reduction_type == EXTRACT_LAST_REDUCTION) + vect_record_loop_mask (loop_vinfo, &LOOP_VINFO_MASKS (loop_vinfo), + ncopies * vec_num, vectype, NULL); + /* Extra inactive lanes should be safe for vect_nested_cycle. */ + else if (STMT_VINFO_DEF_TYPE (reduc_info) != vect_nested_cycle) + { + if (dump_enabled_p ()) + dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, + "conditional reduction prevents the use" + " of partial vectors.\n"); + LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) = false; + } + } STMT_VINFO_TYPE (stmt_info) = condition_vec_info_type; vect_model_simple_cost (vinfo, stmt_info, ncopies, dts, ndts, slp_node, -- 2.30.2