From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id E8FC2385841D for ; Mon, 4 Mar 2024 10:44:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E8FC2385841D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E8FC2385841D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709549046; cv=none; b=rDB0rN2Ey2R0flWZK5UhfTJfa8fy6o2uHyiQc8mgshzNNbin6aWiIDqeZBREixeqWk8JNkI/QbJ3rvBU63K60lpz5L1pfKszW77Q/IUGfwzDGviyn4kSHqHyzL7IzLCu2R6afBgw9Q9yzmMohb4t4M7pJZyEpuX9ICS8aGwHyM0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709549046; c=relaxed/simple; bh=bgptB6zX320FF5nloKCOBIPqgH8vBf7qhFyCnkHelUo=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=uKmbqHonNH9Y+R9LrbwmJaoOXsT7mg7P/GCZ4/ujLSfTvR1zSEz/Wayv0rl8NDgDUBr8l7xmv1KxdXqOP1l2UavNMjCR/VGvEsOwHOeW8T0skWexT+0lWQVIW5act5SguNxHj6VKcD/A9yjDBOi8kjuz+zrVctxtoJojSAPCZE8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.168.4.150] (unknown [10.168.4.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E0D8175A8B for ; Mon, 4 Mar 2024 10:44:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709549044; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=l3Z8g3BMpITGwewHeXTAd4wZPv3t4QQke1KRpTgdYqE=; b=EeAdvm5h5yV9+Wo4kGujxoV4VDg/eqUc0jOqiO+qb9AAzQPPeUDyHp/mdfKFYiVS5qqykx DhdUyE/tKWg1c8tF8z6Qk8uNatPlMqRTaoc63vjaaXwK4jRtho5L39i99AzcraO+nGqzTb ycLLGvQ0lE6aRawav7SL+AR1ibFwgQA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709549044; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=l3Z8g3BMpITGwewHeXTAd4wZPv3t4QQke1KRpTgdYqE=; b=K9FZFZp0coRp1ZPoWLA6rVIoE6jt9PWssaLrJwpHqei8uBD+jWVBjY7Ir7ES6WX+4ekSlC xKYdR9Xgw0xncvCw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1709549043; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=l3Z8g3BMpITGwewHeXTAd4wZPv3t4QQke1KRpTgdYqE=; b=1LgbqKdJvJvQLkhSCVmHFmiBNozhNcuOUCsM1ZC+NNQWocI7MIRSma4JpkDNCFUMuuYVC5 oUBO9y2q7NdKSG6i4RK7q9UiPqivfYi9fzF9mG4tkwBj5h7E0cfou0xC9K7xZUU+xA3Osn jJfT9K0VNXUvZffBMXqunb+pzQfbPCU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1709549043; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=l3Z8g3BMpITGwewHeXTAd4wZPv3t4QQke1KRpTgdYqE=; b=LDfM13f6HorOMA/bGnxkygzmUCLVBoUtEB9H0j8f6TM8BIG8z86PioS2VG+7tmiZ08og4I ae5PKJuqXMLB1HDA== Date: Mon, 4 Mar 2024 11:44:03 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/114192 - scalar reduction kept live with early break vect MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [-0.49 / 50.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; MISSING_MID(2.50)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-2.89)[99.53%] X-Spam-Level: X-Spam-Score: -0.49 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,MISSING_MID,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Message-ID: <20240304104403.QTyRZhxc3HzqlK_gR9CFG4AVY_WT9iMIZA54c70NkgE@z> The following fixes a missing replacement of the reduction value used in the epilog, causing the scalar reduction to be kept live across the early break exit path. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/114192 * tree-vect-loop.cc (vect_create_epilog_for_reduction): Use the appropriate def for the live out stmt in case of an alternate exit. --- gcc/tree-vect-loop.cc | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index 35f1f8c7d42..761cdc67570 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -6066,20 +6066,32 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo, stmt_vec_info single_live_out_stmt[] = { stmt_info }; array_slice live_out_stmts = single_live_out_stmt; - if (slp_reduc) - /* All statements produce live-out values. */ - live_out_stmts = SLP_TREE_SCALAR_STMTS (slp_node); - else if (slp_node) - { - /* The last statement in the reduction chain produces the live-out - value. Note SLP optimization can shuffle scalar stmts to - optimize permutations so we have to search for the last stmt. */ - for (k = 0; k < group_size; ++k) - if (!REDUC_GROUP_NEXT_ELEMENT (SLP_TREE_SCALAR_STMTS (slp_node)[k])) - { - single_live_out_stmt[0] = SLP_TREE_SCALAR_STMTS (slp_node)[k]; - break; - } + if (LOOP_VINFO_EARLY_BREAKS (loop_vinfo) + && loop_exit != LOOP_VINFO_IV_EXIT (loop_vinfo) + /* ??? We should fend this off earlier. For conversions we create + multiple epilogues, one dead. */ + && stmt_info == reduc_info->reduc_def) + { + gcc_assert (!slp_node); + single_live_out_stmt[0] = reduc_info; + } + else + { + if (slp_reduc) + /* All statements produce live-out values. */ + live_out_stmts = SLP_TREE_SCALAR_STMTS (slp_node); + else if (slp_node) + { + /* The last statement in the reduction chain produces the live-out + value. Note SLP optimization can shuffle scalar stmts to + optimize permutations so we have to search for the last stmt. */ + for (k = 0; k < group_size; ++k) + if (!REDUC_GROUP_NEXT_ELEMENT (SLP_TREE_SCALAR_STMTS (slp_node)[k])) + { + single_live_out_stmt[0] = SLP_TREE_SCALAR_STMTS (slp_node)[k]; + break; + } + } } unsigned vec_num; -- 2.35.3