From patchwork Thu Sep 16 06:27:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liuhongt X-Patchwork-Id: 45066 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 0BB173858005 for ; Thu, 16 Sep 2021 06:28:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0BB173858005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1631773729; bh=gIeE8SBvCHRURKlDpx21DxYpAGfLpbZeTLOkMCFEW7I=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=fI6cyxy2NFNLTp5BZW95YYwKRRddiNKKcPjg7Ts2zd3rUHknd7Um/8M94Lb2ziYMT 8s9RjPFR19zHMR/4eytmFp28XvTF9N9S+ajqF4w0+sD9ifD3sgSWZU6w1O8kAylnZq w1pxJbjIfFQAVntGHur6rWgd8sPqKxROkFrAvg7Q= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by sourceware.org (Postfix) with ESMTPS id BACED385781A for ; Thu, 16 Sep 2021 06:27:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BACED385781A X-IronPort-AV: E=McAfee;i="6200,9189,10108"; a="209727914" X-IronPort-AV: E=Sophos;i="5.85,297,1624345200"; d="scan'208";a="209727914" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Sep 2021 23:27:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,297,1624345200"; d="scan'208";a="530061380" Received: from scymds01.sc.intel.com ([10.148.94.138]) by fmsmga004.fm.intel.com with ESMTP; 15 Sep 2021 23:27:46 -0700 Received: from shliclel219.sh.intel.com (shliclel219.sh.intel.com [10.239.236.219]) by scymds01.sc.intel.com with ESMTP id 18G6Ri2l003105; Wed, 15 Sep 2021 23:27:45 -0700 To: gcc-patches@gcc.gnu.org Subject: [PATCH] Check mask type when doing cond_op related gimple simplification. Date: Thu, 16 Sep 2021 14:27:44 +0800 Message-Id: <20210916062744.2387600-1-hongtao.liu@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP 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 Cc: richard.sandiford@arm.com Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Ping. Bootstrapped and regtest on x86_64-linux-gnu{-m32,}, aarch64-unknown-linux-gnu{-m32,} Ok for trunk? gcc/ChangeLog: PR middle-end/102080 * match.pd: Check mask type when doing cond_op related gimple simplification. * tree.c (is_truth_type_for): New function. * tree.h (is_truth_type_for): New declaration. gcc/testsuite/ChangeLog: PR middle-end/102080 * gcc.target/i386/pr102080.c: New test. --- gcc/match.pd | 8 +++---- gcc/testsuite/gcc.target/i386/pr102080.c | 19 ++++++++++++++++ gcc/tree.c | 29 ++++++++++++++++++++++++ gcc/tree.h | 1 + 4 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr102080.c diff --git a/gcc/match.pd b/gcc/match.pd index 008f7758c96..41f9e6d97f0 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -7020,13 +7020,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (vec_cond @0 (view_convert? (uncond_op@4 @1 @2)) @3) (with { tree op_type = TREE_TYPE (@4); } (if (vectorized_internal_fn_supported_p (as_internal_fn (cond_op), op_type) - && element_precision (type) == element_precision (op_type)) + && is_truth_type_for (op_type, TREE_TYPE (@0))) (view_convert (cond_op @0 @1 @2 (view_convert:op_type @3)))))) (simplify (vec_cond @0 @1 (view_convert? (uncond_op@4 @2 @3))) (with { tree op_type = TREE_TYPE (@4); } (if (vectorized_internal_fn_supported_p (as_internal_fn (cond_op), op_type) - && element_precision (type) == element_precision (op_type)) + && is_truth_type_for (op_type, TREE_TYPE (@0))) (view_convert (cond_op (bit_not @0) @2 @3 (view_convert:op_type @1))))))) /* Same for ternary operations. */ @@ -7036,13 +7036,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (vec_cond @0 (view_convert? (uncond_op@5 @1 @2 @3)) @4) (with { tree op_type = TREE_TYPE (@5); } (if (vectorized_internal_fn_supported_p (as_internal_fn (cond_op), op_type) - && element_precision (type) == element_precision (op_type)) + && is_truth_type_for (op_type, TREE_TYPE (@0))) (view_convert (cond_op @0 @1 @2 @3 (view_convert:op_type @4)))))) (simplify (vec_cond @0 @1 (view_convert? (uncond_op@5 @2 @3 @4))) (with { tree op_type = TREE_TYPE (@5); } (if (vectorized_internal_fn_supported_p (as_internal_fn (cond_op), op_type) - && element_precision (type) == element_precision (op_type)) + && is_truth_type_for (op_type, TREE_TYPE (@0))) (view_convert (cond_op (bit_not @0) @2 @3 @4 (view_convert:op_type @1))))))) #endif diff --git a/gcc/testsuite/gcc.target/i386/pr102080.c b/gcc/testsuite/gcc.target/i386/pr102080.c new file mode 100644 index 00000000000..4c5ee32ee63 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr102080.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +#include +typedef float __m256 __attribute__((__vector_size__(32))); +__m256 _mm256_blendv_ps___Y, _mm256_blendv_ps___M, _mm256_mul_ps___A, + _mm256_mul_ps___B, IfThenElse___trans_tmp_9; + +void +__attribute__ ((target("avx"))) +IfThenElse (__m256 no) { + IfThenElse___trans_tmp_9 = _mm256_blendv_ps (no, _mm256_blendv_ps___Y, _mm256_blendv_ps___M); +} +void +__attribute__ ((target("avx512vl"))) +EncodedFromDisplay() { + __m256 __trans_tmp_11 = _mm256_mul_ps___A * _mm256_mul_ps___B; + IfThenElse(__trans_tmp_11); +} diff --git a/gcc/tree.c b/gcc/tree.c index 3d15948fd1a..994775d7314 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -10737,6 +10737,35 @@ signed_type_for (tree type) return signed_or_unsigned_type_for (0, type); } +/* - For VECTOR_TYPEs: + - The truth type must be a VECTOR_BOOLEAN_TYPE. + - The number of elements must match (known_eq). + - targetm.vectorize.get_mask_mode exists, and exactly + the same mode as the truth type. + - Otherwise, the truth type must be a BOOLEAN_TYPE + or useless_type_conversion_p to BOOLEAN_TYPE. */ +bool +is_truth_type_for (tree type, tree truth_type) +{ + machine_mode mask_mode = TYPE_MODE (truth_type); + machine_mode vmode = TYPE_MODE (type); + machine_mode tmask_mode; + + if (TREE_CODE (type) == VECTOR_TYPE) + { + if (VECTOR_BOOLEAN_TYPE_P (truth_type) + && known_eq (TYPE_VECTOR_SUBPARTS (type), + TYPE_VECTOR_SUBPARTS (truth_type)) + && targetm.vectorize.get_mask_mode (vmode).exists (&tmask_mode) + && tmask_mode == mask_mode) + return true; + + return false; + } + + return useless_type_conversion_p (boolean_type_node, truth_type); +} + /* If TYPE is a vector type, return a signed integer vector type with the same width and number of subparts. Otherwise return boolean_type_node. */ diff --git a/gcc/tree.h b/gcc/tree.h index 7274ba75f59..06c027da450 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -4591,6 +4591,7 @@ extern tree build_string_literal (unsigned, const char * = NULL, extern tree signed_or_unsigned_type_for (int, tree); extern tree signed_type_for (tree); extern tree unsigned_type_for (tree); +bool is_truth_type_for (tree, tree); extern tree truth_type_for (tree); extern tree build_pointer_type_for_mode (tree, machine_mode, bool); extern tree build_pointer_type (tree);