From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id E84CB38582A3 for ; Tue, 7 Nov 2023 15:04:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E84CB38582A3 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 E84CB38582A3 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:67c:2178:6::1c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699369450; cv=none; b=wrUJ025jYQR1Z1gnfPgXPFK00XOfgkVws+qNEp/kcgqY4MDnIQPg0ohuwg8ZuRNB25M71l9b54nUu20THJh8N7w2utc5oiVmeBU55SEHDU3hqSc+DMYfDj0XDC7gWqSrkAB5eGrzDhwe8B/5yIzItbq9Ns6jKzgZsMA93XJJ/80= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699369450; c=relaxed/simple; bh=v7f2t408rVZMUIoS4PHAYOQPiSVqbE/CPSJQ8iJJpqQ=; h=DKIM-Signature:DKIM-Signature:Date:From:To:Subject:Message-ID: MIME-Version; b=iSZCb7+iM71Ub7E3+ISyObqwwGJP0xGKsxLMvF0dsUDqC9l9/ANEwBR88x64ldX411pUKk852MGjqBRDKIjtVipSghwfKc4MFRvxkghsAMYDQtzNIHDu+N5NUpG3Z2QkQnZCra7s4ElAGwe09CW0x6xq0p9TMEUpKJRrdhTrvtM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 0F1DD2191E; Tue, 7 Nov 2023 15:04:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1699369447; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Vqgl9cUM2/oPfA+tpLHUKcsbzy4RHNwQQH0W5Oeq7wM=; b=1nX/89Q0QBP6L5D+uI5an6uzPzj+VLIAw9CRdjbWv3uEfPCGi4YwKoil3CsClnCry+0iC6 7p3IhegneM0PqUPer0gcjwkHolu3vZpp269K0HmnSGYGxR87FR53rnFJ0MzRbc9qbZ/4Os 4A8zvqFy+bgSderDSSEGb6V+I+94R8g= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1699369447; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Vqgl9cUM2/oPfA+tpLHUKcsbzy4RHNwQQH0W5Oeq7wM=; b=2WK2RlLtcDaOrc5CR5uYSOHhdUI1O8GjgHeRKkH3vSCwupyqh1vKtTcfSrO5yYghlFxtvm UU7paqfjwBAZ/VCQ== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id BCFCB2CD21; Tue, 7 Nov 2023 15:04:06 +0000 (UTC) Date: Tue, 7 Nov 2023 15:04:06 +0000 (UTC) From: Richard Biener To: Tamar Christina cc: gcc-patches@gcc.gnu.org, nd@arm.com, jlaw@ventanamicro.com Subject: Re: [PATCH 5/21]middle-end: update vectorizer's control update to support picking an exit other than loop latch In-Reply-To: Message-ID: References: User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_LOTSOFHASH,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: On Mon, 6 Nov 2023, Tamar Christina wrote: > Hi All, > > As requested, the vectorizer is now free to pick it's own exit which can be > different than what the loop CFG infrastucture uses. The vectorizer makes use > of this to vectorize loops that it previously could not. > > But this means that loop control must be materialized in the block that needs it > less we corrupt the SSA chain. This makes it so we use the vectorizer's main > IV block instead of the loop infra. > > Bootstrapped Regtested on aarch64-none-linux-gnu and no issues. > > Ok for master? > > Thanks, > Tamar > > gcc/ChangeLog: > > * tree-ssa-loop-manip.cc (standard_iv_increment_position): Conditionally > take dest BB. > * tree-ssa-loop-manip.h (standard_iv_increment_position): Likewise. > * tree-vect-loop-manip.cc (vect_set_loop_controls_directly): Use it. > (vect_set_loop_condition_partial_vectors_avx512): Likewise. > (vect_set_loop_condition_normal): Likewise. > > --- inline copy of patch -- > diff --git a/gcc/tree-ssa-loop-manip.h b/gcc/tree-ssa-loop-manip.h > index bda09f51d5619420331c513a9906831c779fd2b4..5938588c8882d842b00301423df111cbe7bf7ba8 100644 > --- a/gcc/tree-ssa-loop-manip.h > +++ b/gcc/tree-ssa-loop-manip.h > @@ -38,7 +38,8 @@ extern basic_block split_loop_exit_edge (edge, bool = false); > extern basic_block ip_end_pos (class loop *); > extern basic_block ip_normal_pos (class loop *); > extern void standard_iv_increment_position (class loop *, > - gimple_stmt_iterator *, bool *); > + gimple_stmt_iterator *, bool *, > + basic_block = NULL); > extern bool > gimple_duplicate_loop_body_to_header_edge (class loop *, edge, unsigned int, > sbitmap, edge, vec *, int); > diff --git a/gcc/tree-ssa-loop-manip.cc b/gcc/tree-ssa-loop-manip.cc > index e7436915e01297e7af2a3bcf1afd01e014de6f32..bdc7a3d74a788f450ca5dde6c29492ce4d4e4550 100644 > --- a/gcc/tree-ssa-loop-manip.cc > +++ b/gcc/tree-ssa-loop-manip.cc > @@ -792,14 +792,19 @@ ip_normal_pos (class loop *loop) > > /* Stores the standard position for induction variable increment in LOOP > (just before the exit condition if it is available and latch block is empty, > - end of the latch block otherwise) to BSI. INSERT_AFTER is set to true if > - the increment should be inserted after *BSI. */ > + end of the latch block otherwise) to BSI. If DEST_BB is specified then that > + basic block is used as the destination instead of the loop latch source > + block. INSERT_AFTER is set to true if the increment should be inserted after > + *BSI. */ > > void > standard_iv_increment_position (class loop *loop, gimple_stmt_iterator *bsi, > - bool *insert_after) > + bool *insert_after, basic_block dest_bb) > { > - basic_block bb = ip_normal_pos (loop), latch = ip_end_pos (loop); > + basic_block bb = dest_bb; > + if (!bb) > + bb = ip_normal_pos (loop); > + basic_block latch = ip_end_pos (loop); I don't think that's a good API extension. Given that we don't support an early exit after the main IV exit doesn't this code already work fine as-is? It chooses the last exit. The position is also not semantically relevant, we just try to keep the latch empty here (that is, it's a bit of a "bad" API). So, do you really need this change? Maybe we're really using standard_iv_increment_position wrong here, the result is supposed to _only_ feed the PHI latch argument. Richard. > gimple *last = last_nondebug_stmt (latch); > > if (!bb > diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc > index 6fbb5b80986fd657814b48eb009b52b094f331e6..3d59119787d6afdc5a6465a547d1ea2d3d940373 100644 > --- a/gcc/tree-vect-loop-manip.cc > +++ b/gcc/tree-vect-loop-manip.cc > @@ -531,7 +531,8 @@ vect_set_loop_controls_directly (class loop *loop, loop_vec_info loop_vinfo, > tree index_before_incr, index_after_incr; > gimple_stmt_iterator incr_gsi; > bool insert_after; > - standard_iv_increment_position (loop, &incr_gsi, &insert_after); > + edge exit_e = LOOP_VINFO_IV_EXIT (loop_vinfo); > + standard_iv_increment_position (loop, &incr_gsi, &insert_after, exit_e->src); > if (LOOP_VINFO_USING_DECREMENTING_IV_P (loop_vinfo)) > { > /* Create an IV that counts down from niters_total and whose step > @@ -1017,7 +1018,8 @@ vect_set_loop_condition_partial_vectors_avx512 (class loop *loop, > tree index_before_incr, index_after_incr; > gimple_stmt_iterator incr_gsi; > bool insert_after; > - standard_iv_increment_position (loop, &incr_gsi, &insert_after); > + standard_iv_increment_position (loop, &incr_gsi, &insert_after, > + exit_edge->src); > create_iv (niters_adj, MINUS_EXPR, iv_step, NULL_TREE, loop, > &incr_gsi, insert_after, &index_before_incr, > &index_after_incr); > @@ -1185,7 +1187,7 @@ vect_set_loop_condition_partial_vectors_avx512 (class loop *loop, > loop handles exactly VF scalars per iteration. */ > > static gcond * > -vect_set_loop_condition_normal (loop_vec_info /* loop_vinfo */, edge exit_edge, > +vect_set_loop_condition_normal (loop_vec_info loop_vinfo, edge exit_edge, > class loop *loop, tree niters, tree step, > tree final_iv, bool niters_maybe_zero, > gimple_stmt_iterator loop_cond_gsi) > @@ -1278,7 +1280,8 @@ vect_set_loop_condition_normal (loop_vec_info /* loop_vinfo */, edge exit_edge, > } > } > > - standard_iv_increment_position (loop, &incr_gsi, &insert_after); > + standard_iv_increment_position (loop, &incr_gsi, &insert_after, > + exit_edge->src); > create_iv (init, PLUS_EXPR, step, NULL_TREE, loop, > &incr_gsi, insert_after, &indx_before_incr, &indx_after_incr); > indx_after_incr = force_gimple_operand_gsi (&loop_cond_gsi, indx_after_incr, > > > > > -- Richard Biener SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)