From patchwork Thu Sep 29 05:00:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liuhongt X-Patchwork-Id: 1517 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f2ce:0:0:0:0:0 with SMTP id d14csp510267wrp; Wed, 28 Sep 2022 22:03:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM520oI9Dx4t2BVmyZn44JRg9guQWFNxaLcBQA6n4G43I59PH1XyN/EIqeWpZWWHMVg4mQGt X-Received: by 2002:a17:907:31c3:b0:770:852b:71a2 with SMTP id xf3-20020a17090731c300b00770852b71a2mr1103565ejb.557.1664427821572; Wed, 28 Sep 2022 22:03:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664427821; cv=none; d=google.com; s=arc-20160816; b=s9X+SrApikNuPGCzJpcJ9+akxTApTv/yFmqDQ7hFSvxc+GHUUc4ZOPqTMLnQLc2ceN B2eRlLiwvGmYdmQ7//TtKCc2BmJ6Ljqt2OWP3O4ExpLGiD91VfLUuQ/gyBboewKQVbg5 gGkxO8uWIJDibIr8gNCLlNZXyaPCa5P4TEyGAsYQygEu8EihxKupfZ5+++trESzvjNqu JG+O/PfgyIKk9Npq7GALeHSdMcOsrGDC1GVYc08y57mDxVgJNTMZ4tzanPonAoSuk8es QIwb+/fuYvp1qyhgPfQao4GayXcNRV2S4iQQihtUvy6vnwehGdUquXT42zmJ8J+xSuvA 37cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:message-id:date :subject:to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=pBUxyE0chCM+Bij1l15O4i/e8r8dcvBkBitGz1YdSIY=; b=fvgLlPi1Xf3Y9hq3giLl3dnIbpMryjFwKXhmXtdoAybPT9PuIgppLAMbyNYINoBH6w XRsLgJgcFU1xnIaew0EuigsUqeHpikiQgU5gOuz24K5c46janmJ2CNrS6+ZWG5WIAXdL 4obyL0z3ja4SA5CK8OUHxionFLwb8/NShKbbZIrPe3hdQO5goxWyg8rlSa2fLwmzVjyI cVfnyklxYRDYb/rTBDJFqnhfReZdzkDKBsI4yAFNo7ubQw5/TFjW0zKkm1OQBoEL7D0O 1MvxnPH+yhykfM26UX1ErgeN1MyqydlJ2TJ+QV98CnMVycHga1C1iK9li2qquQb5zE+2 l37g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=NjVIZlFx; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id l12-20020a170906794c00b0072f38ecf74asi6720952ejo.794.2022.09.28.22.03.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Sep 2022 22:03:41 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=NjVIZlFx; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 080E33858421 for ; Thu, 29 Sep 2022 05:03:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 080E33858421 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664427820; bh=pBUxyE0chCM+Bij1l15O4i/e8r8dcvBkBitGz1YdSIY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=NjVIZlFxCL5BY/QhE44OUOgm/yEaAx6bBPwT0U+1uXvyK7I7d15lD1G0SVAaH0QXU nw6nsN+MkjNy2+u9Fqs0SsEsEbxt1+fYeaRgOGAHUGobzFM0cddzmJjWMXVpVqKu2q PI0sJyepCW+w3B/VgugQkbZTaOSEHDA0z2LqfDDw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by sourceware.org (Postfix) with ESMTPS id 5A7553858C83 for ; Thu, 29 Sep 2022 05:02:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5A7553858C83 X-IronPort-AV: E=McAfee;i="6500,9779,10484"; a="388075616" X-IronPort-AV: E=Sophos;i="5.93,354,1654585200"; d="scan'208";a="388075616" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2022 22:02:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10484"; a="690671219" X-IronPort-AV: E=Sophos;i="5.93,354,1654585200"; d="scan'208";a="690671219" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by fmsmga004.fm.intel.com with ESMTP; 28 Sep 2022 22:02:52 -0700 Received: from shliclel320.sh.intel.com (shliclel320.sh.intel.com [10.239.240.127]) by shvmail03.sh.intel.com (Postfix) with ESMTP id 7941010056AE; Thu, 29 Sep 2022 13:02:51 +0800 (CST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] Check nonlinear iv in vect_can_advance_ivs_p. Date: Thu, 29 Sep 2022 13:00:51 +0800 Message-Id: <20220929050051.30330-1-hongtao.liu@intel.com> X-Mailer: git-send-email 2.18.1 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: liuhongt via Gcc-patches From: liuhongt Reply-To: liuhongt Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1745279067213417153?= X-GMAIL-MSGID: =?utf-8?q?1745279067213417153?= 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? 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);