From patchwork Tue Sep 20 23:38:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liuhongt X-Patchwork-Id: 1680391 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=D/ni5vGL; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MXJ330v0dz1yqL for ; Wed, 21 Sep 2022 09:41:18 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EEABB3857C49 for ; Tue, 20 Sep 2022 23:41:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EEABB3857C49 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663717275; bh=meHUeF+IR8R7x0pbmzjzdsrsHjP4wmNM+2E4mm0J3S4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=D/ni5vGLS6GKEsdF5pkUwPz45A9IkOARPoVn80pgj+0artDU2lTH1b6/e1B5kesCD tsG/0R5mnov0h/XlUWf1NpIdp+BuW75dembE3stBRY2sam1HjcyAaxXUVJqvzYQhuh K7tfdv0pb26RopodL/deRQmzbv95zUezOGYHkaS8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by sourceware.org (Postfix) with ESMTPS id CD58A3858C55 for ; Tue, 20 Sep 2022 23:40:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CD58A3858C55 X-IronPort-AV: E=McAfee;i="6500,9779,10476"; a="297444041" X-IronPort-AV: E=Sophos;i="5.93,331,1654585200"; d="scan'208";a="297444041" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Sep 2022 16:40:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,331,1654585200"; d="scan'208";a="864179042" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by fmsmga006.fm.intel.com with ESMTP; 20 Sep 2022 16:40:36 -0700 Received: from shliclel320.sh.intel.com (shliclel320.sh.intel.com [10.239.240.127]) by shvmail03.sh.intel.com (Postfix) with ESMTP id AE139100513A; Wed, 21 Sep 2022 07:40:35 +0800 (CST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] Don't check can_vec_perm_const_p for nonlinear iv_init when it's constant. Date: Wed, 21 Sep 2022 07:38:35 +0800 Message-Id: <20220920233835.45071-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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" When init_expr is INTEGER_CST or REAL_CST, can_vec_perm_const_p is not necessary since there's no real vec_perm needed, but vec_gen_perm_mask_checked will gcc_assert (can_vec_perm_const_p). So it's better to use vec_gen_perm_mask_any in vect_create_nonlinear_iv_init. Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}. Ok for trunk? gcc/ChangeLog: PR tree-optimization/106963 * tree-vect-loop.cc (vect_create_nonlinear_iv_init): Use vec_gen_perm_mask_any instead of vec_gen_perm_mask_check. gcc/testsuite/ChangeLog: * gcc.target/i386/pr106963.c: New test. --- gcc/testsuite/gcc.target/i386/pr106963.c | 14 ++++++++++++++ gcc/tree-vect-loop.cc | 5 ++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr106963.c diff --git a/gcc/testsuite/gcc.target/i386/pr106963.c b/gcc/testsuite/gcc.target/i386/pr106963.c new file mode 100644 index 00000000000..9f2d20e2523 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr106963.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mavx -mno-avx2" } */ + +void +foo_neg_const (int *a) +{ + int i, b = 1; + + for (i = 0; i < 1000; i++) + { + a[i] = b; + b = -b; + } +} diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index 9c434b66c5b..aabdc6f2d81 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -8356,8 +8356,11 @@ vect_create_nonlinear_iv_init (gimple_seq* stmts, tree init_expr, sel[2 * i + 1] = i + nunits; } vec_perm_indices indices (sel, 2, nunits); + /* Don't use vect_gen_perm_mask_checked since can_vec_perm_const_p may + fail when vec_init is const vector. In that situation vec_perm is not + really needed. */ tree perm_mask_even - = vect_gen_perm_mask_checked (vectype, indices); + = vect_gen_perm_mask_any (vectype, indices); vec_init = gimple_build (stmts, VEC_PERM_EXPR, vectype, vec_init, vec_neg,