From patchwork Thu Feb 2 01:30:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liuhongt X-Patchwork-Id: 51626 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp616546wrn; Wed, 1 Feb 2023 17:33:45 -0800 (PST) X-Google-Smtp-Source: AK7set9vGfVgvb4PaIaZ8qItVYZHIJGolzXH3jIeqIQlt6s8oKBEQDTF5NpluIghkW4o1CbVQdtP X-Received: by 2002:a17:906:5945:b0:888:787d:2064 with SMTP id g5-20020a170906594500b00888787d2064mr4392212ejr.75.1675301625024; Wed, 01 Feb 2023 17:33:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675301625; cv=none; d=google.com; s=arc-20160816; b=T2tuk0zh7ShiADdYc5/W6qHYeyZA9ApXr1c6IE3HvxFHMf41xxJyjUN2JVI+mQxh2z g+DJIPre1nLHAyJJlbKhV/fPaL9LUFqHeKkvvvrevWb0CIs9TxMwl6IZ0nLPf1rZAjFN 5pctyzu+31LfUck2d36m+SKgt6PEimicGuu/VwPuPC9BjKX8Kuhnl8kaqA7+x9FNd1hX k3QeQGoNI13xIlPTam8VwOhshEsYQpuNmB2X0iDfcfsEPEHeLaoOJ23hqyga+v+fj6lW duH8oF210ZzQJunuI1hbt61TI1FbDYBWmJ4pyTiSNLwP/5T+XhWm7G0jmaM4xe/4C/Dx aMlg== 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 :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=eNE4knnt64vzWTp1n1XKf9136TWpzgvSY/JiCLaIUgk=; b=FTHA2GjVeSYLncz7/herGSLIV5E/Sz3jhE8uPbS9APHoT72nYBOpiDm4M3jkfRyrh9 fyNZ3Ef3Zguzagtc0/Hl4cyo1k1XhTMgVQzUMRw6nGVhaUk8mvmzI1YQOAjAcQ95ObSf gC16mEwRy4G49fe52nfgSlXJg7uK751yylqE96/zFQDBPc0oshmxVy3OV21OHlujysGL wLpgMYq5Ahtsogi0YNJ6MKDZPGjmY74dI8qe/pZsm/DOOKsTrEzijmJ5+c3PjoUUMOxW tDZDvpbrz6xCzlHragSwbAz2A05pa56l3Kge4EWwzP+P6qDWMNC3mVk0wVm649AQMHVE N7OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=CicF+IUZ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ex1-20020a170907954100b0087877581bfcsi18194213ejc.982.2023.02.01.17.33.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 17:33:45 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=CicF+IUZ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 1CC8838582A1 for ; Thu, 2 Feb 2023 01:33:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1CC8838582A1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675301624; bh=eNE4knnt64vzWTp1n1XKf9136TWpzgvSY/JiCLaIUgk=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=CicF+IUZDhU3KNYPIO4/CEXU6Sup33BhSHrTKFmEO7fRScMs3BHR0+LQzWVLyve91 RKjujJEH2003Ep9J0tpb1ZiVqfBL5eck0+ptcjmuxQytpvSA6ygAKLSEkD1aogsCoa QA20vXU79WcJXcxHy3zM/dTD0YCXayZzioHaF66o= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by sourceware.org (Postfix) with ESMTPS id 3CB963858D3C for ; Thu, 2 Feb 2023 01:32:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3CB963858D3C X-IronPort-AV: E=McAfee;i="6500,9779,10608"; a="329613624" X-IronPort-AV: E=Sophos;i="5.97,266,1669104000"; d="scan'208";a="329613624" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2023 17:32:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10608"; a="733769634" X-IronPort-AV: E=Sophos;i="5.97,266,1669104000"; d="scan'208";a="733769634" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by fmsmga004.fm.intel.com with ESMTP; 01 Feb 2023 17:32:52 -0800 Received: from shliclel4217.sh.intel.com (shliclel4217.sh.intel.com [10.239.240.127]) by shvmail03.sh.intel.com (Postfix) with ESMTP id 2503210050EB; Thu, 2 Feb 2023 09:32:52 +0800 (CST) To: gcc-patches@gcc.gnu.org Cc: rguenther@suse.de, tamar.christina@arm.com Subject: [PATCH] [vect] Don't peel nonlinear iv(mult or shift) for epilog when vf is not constant. Date: Thu, 2 Feb 2023 09:30:52 +0800 Message-Id: <20230202013052.2070569-1-hongtao.liu@intel.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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?1756681077013442508?= X-GMAIL-MSGID: =?utf-8?q?1756681077013442508?= Normally when vf is not constant, it will be prevented by vectorizable_nonlinear_inductions, but for this case, it failed going into if (STMT_VINFO_RELEVANT_P (stmt_info)) { need_to_vectorize = true; if (STMT_VINFO_DEF_TYPE (stmt_info) == vect_induction_def && ! PURE_SLP_STMT (stmt_info)) ok = vectorizable_induction (loop_vinfo, stmt_info, NULL, NULL, &cost_vec); since the iv is never used outside of the loop, and will be dce later, so vectorizer doesn't bother checking if it's vectorizable. it's true but hit gcc_assert in vect_can_peel_nonlinear_iv_p when vf is not constant. One solution is ignoring the nonlinear iv peeling if it's !STMT_VINFO_RELEVANT_P (stmt_info) just like the upper code, the other solution is returning false earlier in the vect_can_peel_nonlinear_iv_p when vf is not constant, the patch chooses the second incase there's other cases using vect_can_advance_ivs_p which calls vect_can_peel_nonlinear_iv_p. Also remove vect_can_peel_nonlinear_iv_p from vectorizable_nonlinear_inductions. Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,} and aarch64-linux-gnu{-m32,} Ok for trunk? gcc/ChangeLog: PR tree-optimization/108601 * tree-vectorizer.h (vect_can_peel_nonlinear_iv_p): Remove declare. * tree-vect-loop.cc (vectorizable_nonlinear_induction): Remove vect_can_peel_nonlinear_iv_p. (vect_can_peel_nonlinear_iv_p): Don't peel nonlinear iv(mult or shift) for epilog when vf is not constant and moved the defination to .. * tree-vect-loop-manip.cc (vect_can_peel_nonlinear_iv_p): .. Here. gcc/testsuite/ChangeLog: * gcc.target/aarch64/pr108601.c: New test. --- gcc/testsuite/gcc.target/aarch64/pr108601.c | 11 +++++ gcc/tree-vect-loop-manip.cc | 44 ++++++++++++++++++++ gcc/tree-vect-loop.cc | 46 --------------------- gcc/tree-vectorizer.h | 3 -- 4 files changed, 55 insertions(+), 49 deletions(-) create mode 100644 gcc/testsuite/gcc.target/aarch64/pr108601.c diff --git a/gcc/testsuite/gcc.target/aarch64/pr108601.c b/gcc/testsuite/gcc.target/aarch64/pr108601.c new file mode 100644 index 00000000000..deb8b3061d8 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/pr108601.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -fprofile-generate -mcpu=neoverse-v1" } */ + +int +foo() { + int flag = 1; + for (; flag <= 1 << 21; flag <<= 1) + ; + return 0; +} + diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc index b5c5f859144..c04fcf40c44 100644 --- a/gcc/tree-vect-loop-manip.cc +++ b/gcc/tree-vect-loop-manip.cc @@ -1390,6 +1390,50 @@ iv_phi_p (stmt_vec_info stmt_info) return true; } +/* Return true if vectorizer can peel for nonlinear iv. */ +static 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 or vf 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) + || !LOOP_VINFO_VECT_FACTOR (loop_vinfo).is_constant ()) + && 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 vect_can_advance_ivs_p In case the number of iterations that LOOP iterates is unknown at compile diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index f0801c23671..01b60a8de33 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -8808,49 +8808,6 @@ vect_update_nonlinear_iv (gimple_seq* stmts, tree vectype, } -/* 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 @@ -8921,9 +8878,6 @@ vectorizable_nonlinear_induction (loop_vec_info loop_vinfo, return false; } - if (!vect_can_peel_nonlinear_iv_p (loop_vinfo, induction_type)) - return false; - if (!INTEGRAL_TYPE_P (TREE_TYPE (vectype))) { if (dump_enabled_p ()) diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h index a2aa71bedc0..4ba653712e9 100644 --- a/gcc/tree-vectorizer.h +++ b/gcc/tree-vectorizer.h @@ -2347,9 +2347,6 @@ 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);