From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by sourceware.org (Postfix) with ESMTPS id 8D6183858D28 for ; Thu, 29 Sep 2022 06:36:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8D6183858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-x52e.google.com with SMTP id a13so674847edj.0 for ; Wed, 28 Sep 2022 23:36:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=o6zWYiREA1oyWuDe4eHvECtlrkjfwXBT/ktSHX2RF7g=; b=SkSK26jY/DEWNP9x7fJ5EXtbOXWhlZRw94S+wyGYeUCn/BsqboU8Ozfd2i2+2t/wCt TNDUQu/R/GvlZapLd59C3DNo2Q4o9PsUNmys3XSQYlPO0XZhkUN3xGpy2IiLuc5TPY6P Y+M13rV3mCO7wwDPbEwtY6J7KRhmqyj3jK5i2Xjl1GqfiFItpZLdR7meKYc5J+RSdffe HQODBFCWjBRVc1cobxkquWjdVXqy7Xj+hMndnEUyWFI1gVgsLmnpP1HRKp6aaom9+ivQ z4XTTk93ApFnIwOVyaqlLonUsif3GReVMXpIo9MLE8N4MgtpZhsOkHCoUJwldEUl5ru7 7EzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=o6zWYiREA1oyWuDe4eHvECtlrkjfwXBT/ktSHX2RF7g=; b=IbmnIRI5BHYkMSGSt/51dfL8T52rtVBwnPs/1uq70GqSooitY348Z548K/AZnCmiAF 5i/UcxtUbj/msGhBLAWzwDuVTHlQleti71qBfXXBteIMIFnUvm2FM9xSz1SDhDbM41+e imm6yR4YADPSSHF6SNVzJR36mNfq9t3TPAAxN+cUUHCdq2BY+qa0wBDCHGPhHyFhJdRr FTaPa29DqXKXGJ+LxNXY/HDAc5zxBQHL0Up7Hha41z1yIT6OseVpPspVnYraDyqQ5NAb WDNyfMzPqxeH5+hrKjjBUhSH6Hv9yw05bN9RcY61MaP4gRuQHDRMoAM2jbqH1EEhMX3i BOOw== X-Gm-Message-State: ACrzQf3nXP2vTmWClnG3NsxuyhNpeNuWSbKEtyp20kYNRDgn8r9ckCn4 jLSgVmPjMFjFxg2umWANMdlCVVsYUyEZMUkhWgk= X-Google-Smtp-Source: AMsMyM7i7cybglBRbF66LW90HkxlflN/bBQbhi8tya1g3c3qBPhuBGUAJpGv0tIpjkDVT/hczxDyty5dXFKFu2OnpZg= X-Received: by 2002:a05:6402:1c83:b0:457:dcb2:4240 with SMTP id cy3-20020a0564021c8300b00457dcb24240mr1707206edb.94.1664433366601; Wed, 28 Sep 2022 23:36:06 -0700 (PDT) MIME-Version: 1.0 References: <20220929050051.30330-1-hongtao.liu@intel.com> In-Reply-To: <20220929050051.30330-1-hongtao.liu@intel.com> From: Richard Biener Date: Thu, 29 Sep 2022 08:35:53 +0200 Message-ID: Subject: Re: [PATCH] Check nonlinear iv in vect_can_advance_ivs_p. To: liuhongt Cc: gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP 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, Sep 29, 2022 at 7:03 AM liuhongt via Gcc-patches wrote: > > vectorizable_nonlinear_induction doesn't always guard > vect_peel_nonlinear_iv_init when it's called by > vect_update_ivs_after_vectorizer which is supposed to be guarded > by vect_can_advance_ivs_p. The patch put part codes from > vectorizable_nonlinear_induction into a new function > vect_can_peel_nonlinear_iv_p, and make vect_can_advcance_ivs_p call it. > > Also this patch fix a typo in my initial patch as bellow. > - if (!LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo) > - && induction_type == vect_step_op_mul) > if (!INTEGRAL_TYPE_P (TREE_TYPE (vectype))) > > Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}. > Ok for trunk? OK. Thanks, Richard. > gcc/ChangeLog: > > PR tree-optimization/107055 > * tree-vect-loop-manip.cc (vect_can_advance_ivs_p): Check for > nonlinear induction variables. > * tree-vect-loop.cc (vect_can_peel_nonlinear_iv_p): New > functions. > (vectorizable_nonlinear_induction): Put part codes into > vect_can_peel_nonlinear_iv_p. > * tree-vectorizer.h (vect_can_peel_nonlinear_iv_p): Declare. > > gcc/testsuite/ChangeLog: > > * gcc.target/i386/pr107055.c: New test. > --- > gcc/testsuite/gcc.target/i386/pr107055.c | 4 ++ > gcc/tree-vect-loop-manip.cc | 10 +++ > gcc/tree-vect-loop.cc | 82 ++++++++++++++---------- > gcc/tree-vectorizer.h | 3 + > 4 files changed, 64 insertions(+), 35 deletions(-) > create mode 100644 gcc/testsuite/gcc.target/i386/pr107055.c > > diff --git a/gcc/testsuite/gcc.target/i386/pr107055.c b/gcc/testsuite/gcc.target/i386/pr107055.c > new file mode 100644 > index 00000000000..63bcb3d742e > --- /dev/null > +++ b/gcc/testsuite/gcc.target/i386/pr107055.c > @@ -0,0 +1,4 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O1 -fno-tree-dce -fno-vect-cost-model -ftree-vectorize -fprofile-arcs" } */ > + > +#include "../../gcc.dg/torture/pr24257.c" > diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc > index 74b221a973c..1d96130c985 100644 > --- a/gcc/tree-vect-loop-manip.cc > +++ b/gcc/tree-vect-loop-manip.cc > @@ -1413,6 +1413,7 @@ vect_can_advance_ivs_p (loop_vec_info loop_vinfo) > for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) > { > tree evolution_part; > + enum vect_induction_op_type induction_type; > > gphi *phi = gsi.phi (); > stmt_vec_info phi_info = loop_vinfo->lookup_stmt (phi); > @@ -1432,6 +1433,15 @@ vect_can_advance_ivs_p (loop_vec_info loop_vinfo) > continue; > } > > + induction_type = STMT_VINFO_LOOP_PHI_EVOLUTION_TYPE (phi_info); > + if (induction_type != vect_step_op_add) > + { > + if (!vect_can_peel_nonlinear_iv_p (loop_vinfo, induction_type)) > + return false; > + > + continue; > + } > + > /* Analyze the evolution function. */ > > evolution_part = STMT_VINFO_LOOP_PHI_EVOLUTION_PART (phi_info); > diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc > index aabdc6f2d81..2536cc3cf49 100644 > --- a/gcc/tree-vect-loop.cc > +++ b/gcc/tree-vect-loop.cc > @@ -8558,6 +8558,50 @@ vect_update_nonlinear_iv (gimple_seq* stmts, tree vectype, > return vec_def; > > } > + > +/* Return true if vectorizer can peel for nonlinear iv. */ > +bool > +vect_can_peel_nonlinear_iv_p (loop_vec_info loop_vinfo, > + enum vect_induction_op_type induction_type) > +{ > + tree niters_skip; > + /* Init_expr will be update by vect_update_ivs_after_vectorizer, > + if niters is unkown: > + For shift, when shift mount >= precision, there would be UD. > + For mult, don't known how to generate > + init_expr * pow (step, niters) for variable niters. > + For neg, it should be ok, since niters of vectorized main loop > + will always be multiple of 2. */ > + if (!LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo) > + && induction_type != vect_step_op_neg) > + { > + if (dump_enabled_p ()) > + dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, > + "Peeling for epilogue is not supported" > + " for nonlinear induction except neg" > + " when iteration count is unknown.\n"); > + return false; > + } > + > + /* Also doens't support peel for neg when niter is variable. > + ??? generate something like niter_expr & 1 ? init_expr : -init_expr? */ > + niters_skip = LOOP_VINFO_MASK_SKIP_NITERS (loop_vinfo); > + if ((niters_skip != NULL_TREE > + && TREE_CODE (niters_skip) != INTEGER_CST) > + || (!vect_use_loop_mask_for_alignment_p (loop_vinfo) > + && LOOP_VINFO_PEELING_FOR_ALIGNMENT (loop_vinfo) < 0)) > + { > + if (dump_enabled_p ()) > + dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, > + "Peeling for alignement is not supported" > + " for nonlinear induction when niters_skip" > + " is not constant.\n"); > + return false; > + } > + > + return true; > +} > + > /* Function vectorizable_induction > > Check if STMT_INFO performs an nonlinear induction computation that can be > @@ -8628,42 +8672,9 @@ vectorizable_nonlinear_induction (loop_vec_info loop_vinfo, > return false; > } > > - /* Init_expr will be update by vect_update_ivs_after_vectorizer, > - if niters is unkown: > - For shift, when shift mount >= precision, there would be UD. > - For mult, don't known how to generate > - init_expr * pow (step, niters) for variable niters. > - For neg, it should be ok, since niters of vectorized main loop > - will always be multiple of 2. */ > - if (!LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo) > - && induction_type != vect_step_op_neg) > - { > - if (dump_enabled_p ()) > - dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, > - "Peeling for epilogue is not supported" > - " for nonlinear induction except neg" > - " when iteration count is unknown.\n"); > - return false; > - } > - > - /* Also doens't support peel for neg when niter is variable. > - ??? generate something like niter_expr & 1 ? init_expr : -init_expr? */ > - niters_skip = LOOP_VINFO_MASK_SKIP_NITERS (loop_vinfo); > - if ((niters_skip != NULL_TREE > - && TREE_CODE (niters_skip) != INTEGER_CST) > - || (!vect_use_loop_mask_for_alignment_p (loop_vinfo) > - && LOOP_VINFO_PEELING_FOR_ALIGNMENT (loop_vinfo) < 0)) > - { > - if (dump_enabled_p ()) > - dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location, > - "Peeling for alignement is not supported" > - " for nonlinear induction when niters_skip" > - " is not constant.\n"); > - return false; > - } > + if (!vect_can_peel_nonlinear_iv_p (loop_vinfo, induction_type)) > + return false; > > - if (!LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo) > - && induction_type == vect_step_op_mul) > if (!INTEGRAL_TYPE_P (TREE_TYPE (vectype))) > { > if (dump_enabled_p ()) > @@ -8799,6 +8810,7 @@ vectorizable_nonlinear_induction (loop_vec_info loop_vinfo, > > gimple_seq stmts = NULL; > > + niters_skip = LOOP_VINFO_MASK_SKIP_NITERS (loop_vinfo); > /* If we are using the loop mask to "peel" for alignment then we need > to adjust the start value here. */ > if (niters_skip != NULL_TREE) > diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h > index 5e75ed1532b..4870c754499 100644 > --- a/gcc/tree-vectorizer.h > +++ b/gcc/tree-vectorizer.h > @@ -2343,6 +2343,9 @@ extern tree cse_and_gimplify_to_preheader (loop_vec_info, tree); > /* Nonlinear induction. */ > extern tree vect_peel_nonlinear_iv_init (gimple_seq*, tree, tree, > tree, enum vect_induction_op_type); > +extern bool > +vect_can_peel_nonlinear_iv_p (loop_vec_info loop_vinfo, > + enum vect_induction_op_type induction_type); > > /* In tree-vect-slp.cc. */ > extern void vect_slp_init (void); > -- > 2.18.1 >