From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 6BDF838558BE for ; Fri, 2 Jun 2023 08:56:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6BDF838558BE Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id A132721A37; Fri, 2 Jun 2023 08:56:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1685696175; 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=mo5ekc8w/36R9rTnL0MH7ggjCDWbgWyWh4upWKfaw8o=; b=Rk5IYFNYk2ntxHMz476cbp1ZINZ1fghNz8zIvSb3hFTIuw0xJsoHblM2G1x2VKE+RIvw2f ihlwEd4L2p8BVeH7d8jpHCaAnteHVXDXXfyws+KlrD+GvuqgiRv+d6Pdj03yQ62WAVHacV +YgmzDC7OfEuAweXK0AaXUEvi+wEMig= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1685696175; 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=mo5ekc8w/36R9rTnL0MH7ggjCDWbgWyWh4upWKfaw8o=; b=Ij28tPALc6Do0quPLR2ZVoz8HBaITxC4wjvQ0dOK2GPvm2iAc/vDFG7MD0tiq3/GZJr6nk TzsfXC3bdGU4VdCw== 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 89A8F2C141; Fri, 2 Jun 2023 08:56:15 +0000 (UTC) Date: Fri, 2 Jun 2023 08:56:15 +0000 (UTC) From: Richard Biener To: "juzhe.zhong@rivai.ai" cc: gcc-patches , "richard.sandiford" , linkw Subject: Re: [PATCH V3] VECT: Change flow of decrement IV In-Reply-To: <489BFF1AE94B6B81+2023060113000785279135@rivai.ai> Message-ID: References: <20230601043617.173986-1-juzhe.zhong@rivai.ai> <489BFF1AE94B6B81+2023060113000785279135@rivai.ai> 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,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 Thu, 1 Jun 2023, juzhe.zhong@rivai.ai wrote: > This patch is no difference from V2. > Just add PR tree-optimization/109971 as Kewen's suggested. > > Already bootstrapped and Regression on X86 no difference. > > Ok for trunk ? OK. Richard. > > juzhe.zhong@rivai.ai > > From: juzhe.zhong > Date: 2023-06-01 12:36 > To: gcc-patches > CC: richard.sandiford; rguenther; linkw; Ju-Zhe Zhong > Subject: [PATCH V3] VECT: Change flow of decrement IV > From: Ju-Zhe Zhong > > Follow Richi's suggestion, I change current decrement IV flow from: > > do { > remain -= MIN (vf, remain); > } while (remain != 0); > > into: > > do { > old_remain = remain; > len = MIN (vf, remain); > remain -= vf; > } while (old_remain >= vf); > > to enhance SCEV. > > Include fixes from kewen. > > > This patch will need to wait for Kewen's test feedback. > > Testing on X86 is on-going > > Co-Authored by: Kewen Lin > > PR tree-optimization/109971 > > gcc/ChangeLog: > > * tree-vect-loop-manip.cc (vect_set_loop_controls_directly): Change decrement IV flow. > (vect_set_loop_condition_partial_vectors): Ditto. > > --- > gcc/tree-vect-loop-manip.cc | 36 +++++++++++++++++++++++++----------- > 1 file changed, 25 insertions(+), 11 deletions(-) > > diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc > index acf3642ceb2..3f735945e67 100644 > --- a/gcc/tree-vect-loop-manip.cc > +++ b/gcc/tree-vect-loop-manip.cc > @@ -483,7 +483,7 @@ vect_set_loop_controls_directly (class loop *loop, loop_vec_info loop_vinfo, > gimple_stmt_iterator loop_cond_gsi, > rgroup_controls *rgc, tree niters, > tree niters_skip, bool might_wrap_p, > - tree *iv_step) > + tree *iv_step, tree *compare_step) > { > tree compare_type = LOOP_VINFO_RGROUP_COMPARE_TYPE (loop_vinfo); > tree iv_type = LOOP_VINFO_RGROUP_IV_TYPE (loop_vinfo); > @@ -538,9 +538,9 @@ vect_set_loop_controls_directly (class loop *loop, loop_vec_info loop_vinfo, > ... > vect__4.8_28 = .LEN_LOAD (_17, 32B, _36, 0); > ... > - ivtmp_35 = ivtmp_9 - _36; > + ivtmp_35 = ivtmp_9 - POLY_INT_CST [4, 4]; > ... > - if (ivtmp_35 != 0) > + if (ivtmp_9 > POLY_INT_CST [4, 4]) > goto ; [83.33%] > else > goto ; [16.67%] > @@ -549,13 +549,15 @@ vect_set_loop_controls_directly (class loop *loop, loop_vec_info loop_vinfo, > tree step = rgc->controls.length () == 1 ? rgc->controls[0] > : make_ssa_name (iv_type); > /* Create decrement IV. */ > - create_iv (nitems_total, MINUS_EXPR, step, NULL_TREE, loop, &incr_gsi, > - insert_after, &index_before_incr, &index_after_incr); > + create_iv (nitems_total, MINUS_EXPR, nitems_step, NULL_TREE, loop, > + &incr_gsi, insert_after, &index_before_incr, > + &index_after_incr); > gimple_seq_add_stmt (header_seq, gimple_build_assign (step, MIN_EXPR, > index_before_incr, > nitems_step)); > *iv_step = step; > - return index_after_incr; > + *compare_step = nitems_step; > + return index_before_incr; > } > /* Create increment IV. */ > @@ -825,6 +827,7 @@ vect_set_loop_condition_partial_vectors (class loop *loop, > arbitrarily pick the last. */ > tree test_ctrl = NULL_TREE; > tree iv_step = NULL_TREE; > + tree compare_step = NULL_TREE; > rgroup_controls *rgc; > rgroup_controls *iv_rgc = nullptr; > unsigned int i; > @@ -861,7 +864,7 @@ vect_set_loop_condition_partial_vectors (class loop *loop, > &preheader_seq, &header_seq, > loop_cond_gsi, rgc, niters, > niters_skip, might_wrap_p, > - &iv_step); > + &iv_step, &compare_step); > iv_rgc = rgc; > } > @@ -884,10 +887,21 @@ vect_set_loop_condition_partial_vectors (class loop *loop, > /* Get a boolean result that tells us whether to iterate. */ > edge exit_edge = single_exit (loop); > - tree_code code = (exit_edge->flags & EDGE_TRUE_VALUE) ? EQ_EXPR : NE_EXPR; > - tree zero_ctrl = build_zero_cst (TREE_TYPE (test_ctrl)); > - gcond *cond_stmt = gimple_build_cond (code, test_ctrl, zero_ctrl, > - NULL_TREE, NULL_TREE); > + gcond *cond_stmt; > + if (LOOP_VINFO_USING_DECREMENTING_IV_P (loop_vinfo)) > + { > + gcc_assert (compare_step); > + tree_code code = (exit_edge->flags & EDGE_TRUE_VALUE) ? LE_EXPR : GT_EXPR; > + cond_stmt = gimple_build_cond (code, test_ctrl, compare_step, NULL_TREE, > + NULL_TREE); > + } > + else > + { > + tree_code code = (exit_edge->flags & EDGE_TRUE_VALUE) ? EQ_EXPR : NE_EXPR; > + tree zero_ctrl = build_zero_cst (TREE_TYPE (test_ctrl)); > + cond_stmt > + = gimple_build_cond (code, test_ctrl, zero_ctrl, NULL_TREE, NULL_TREE); > + } > gsi_insert_before (&loop_cond_gsi, cond_stmt, GSI_SAME_STMT); > /* The loop iterates (NITERS - 1) / VF + 1 times. > -- Richard Biener SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman; HRB 36809 (AG Nuernberg)