From patchwork Wed Feb 16 09:03:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liuhongt X-Patchwork-Id: 51152 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7A98B3857C59 for ; Wed, 16 Feb 2022 09:04:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7A98B3857C59 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1645002294; bh=dhjMDSSS/cuxkMzyPiiuuVMB85zbp9MONYG3iusk4nc=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=BeFqVRx01Vpw6CNdJBxxz3zBzDXWmQRt1Xmo1r66CwzyAhMJfHktbPuNOoq/fNQBd nFwM9sm+SENQkZd1vVnw9CAnT8woqmjwl41KOfpgLrYpXRx2plDldeOx22OTETzkff XP4fOUWHAeO9wov61tDNPS3220iv7EhxACj1YKno= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by sourceware.org (Postfix) with ESMTPS id 4D8383858D37 for ; Wed, 16 Feb 2022 09:04:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4D8383858D37 X-IronPort-AV: E=McAfee;i="6200,9189,10259"; a="313831001" X-IronPort-AV: E=Sophos;i="5.88,373,1635231600"; d="scan'208";a="313831001" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Feb 2022 01:04:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,373,1635231600"; d="scan'208";a="539917895" Received: from scymds01.sc.intel.com ([10.148.94.138]) by fmsmga007.fm.intel.com with ESMTP; 16 Feb 2022 01:04:22 -0800 Received: from shliclel051.sh.intel.com (shliclel051.sh.intel.com [10.239.236.51]) by scymds01.sc.intel.com with ESMTP id 21G9399t004344; Wed, 16 Feb 2022 01:03:09 -0800 To: gcc-patches@gcc.gnu.org Subject: [PATCH] Restrict the two sources of vect_recog_cond_expr_convert_pattern to be of the same type when convert is extension. Date: Wed, 16 Feb 2022 17:03:09 +0800 Message-Id: <20220216090309.82939-1-hongtao.liu@intel.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: References: X-Spam-Status: No, score=-12.3 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" > > +(match (cond_expr_convert_p @0 @2 @3 @6) > > + (cond (simple_comparison@6 @0 @1) (convert@4 @2) (convert@5 @3)) > > + (if (types_match (TREE_TYPE (@2), TREE_TYPE (@3)) > > But in principle @2 or @3 could safely differ in sign, you'd then need to ensure > to insert sign conversions to @2/@3 to the signedness of @4/@5. > It turns out differ in sign is not suitable for extension(but ok for truncation), because it's zero_extend vs sign_extend. The patch add types_match check when convert is extension. Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}. And native Bootstrapped and regtested on CLX. Ok for trunk? gcc/ChangeLog: PR tree-optimization/104551 PR tree-optimization/103771 * match.pd (cond_expr_convert_p): Add types_match check when convert is extension. * tree-vect-patterns.cc (gimple_cond_expr_convert_p): Adjust comments. (vect_recog_cond_expr_convert_pattern): Ditto. gcc/testsuite/ChangeLog: * gcc.target/i386/pr104551.c: New test. --- gcc/match.pd | 8 +++++--- gcc/testsuite/gcc.target/i386/pr104551.c | 24 ++++++++++++++++++++++++ gcc/tree-vect-patterns.cc | 6 ++++-- 3 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr104551.c diff --git a/gcc/match.pd b/gcc/match.pd index 05a10ab6bfd..8e80b9f1576 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -7692,11 +7692,13 @@ and, (if (INTEGRAL_TYPE_P (type) && INTEGRAL_TYPE_P (TREE_TYPE (@2)) && INTEGRAL_TYPE_P (TREE_TYPE (@0)) - && INTEGRAL_TYPE_P (TREE_TYPE (@3)) && TYPE_PRECISION (type) != TYPE_PRECISION (TREE_TYPE (@0)) && TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION (TREE_TYPE (@2)) - && TYPE_PRECISION (TREE_TYPE (@0)) - == TYPE_PRECISION (TREE_TYPE (@3)) + && (types_match (TREE_TYPE (@2), TREE_TYPE (@3)) + || ((TYPE_PRECISION (TREE_TYPE (@0)) + == TYPE_PRECISION (TREE_TYPE (@3))) + && INTEGRAL_TYPE_P (TREE_TYPE (@3)) + && TYPE_PRECISION (TREE_TYPE (@3)) > TYPE_PRECISION (type))) && single_use (@4) && single_use (@5)))) diff --git a/gcc/testsuite/gcc.target/i386/pr104551.c b/gcc/testsuite/gcc.target/i386/pr104551.c new file mode 100644 index 00000000000..6300f25c0d5 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr104551.c @@ -0,0 +1,24 @@ +/* { dg-do run } */ +/* { dg-options "-O3 -mavx2" } */ +/* { dg-require-effective-target avx2 } */ + +unsigned int +__attribute__((noipa)) +test(unsigned int a, unsigned char p[16]) { + unsigned int res = 0; + for (unsigned b = 0; b < a; b += 1) + res = p[b] ? p[b] : (char) b; + return res; +} + +int main () +{ + unsigned int a = 16U; + unsigned char p[16]; + for (int i = 0; i != 16; i++) + p[i] = (unsigned char)128; + unsigned int res = test (a, p); + if (res != 128) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc index a8f96d59643..217bdfd7045 100644 --- a/gcc/tree-vect-patterns.cc +++ b/gcc/tree-vect-patterns.cc @@ -929,8 +929,10 @@ vect_reassociating_reduction_p (vec_info *vinfo, with conditions: 1) @1, @2, c, d, a, b are all integral type. 2) There's single_use for both @1 and @2. - 3) a, c and d have same precision. + 3) a, c have same precision. 4) c and @1 have different precision. + 5) c, d are the same type or they can differ in sign when convert is + truncation. record a and c and d and @3. */ @@ -952,7 +954,7 @@ extern bool gimple_cond_expr_convert_p (tree, tree*, tree (*)(tree)); TYPE_PRECISION (TYPE_E) != TYPE_PRECISION (TYPE_CD); TYPE_PRECISION (TYPE_AB) == TYPE_PRECISION (TYPE_CD); single_use of op_true and op_false. - TYPE_AB could differ in sign. + TYPE_AB could differ in sign when (TYPE_E) A is a truncation. Input: