From patchwork Mon Aug 26 07:33:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liuhongt X-Patchwork-Id: 1976676 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=JD077yDv; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wsj8w66sNz1yfF for ; Mon, 26 Aug 2024 17:33:51 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8D840384AB4D for ; Mon, 26 Aug 2024 07:33:49 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by sourceware.org (Postfix) with ESMTPS id B46BA3858D29 for ; Mon, 26 Aug 2024 07:33:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B46BA3858D29 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B46BA3858D29 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724657603; cv=none; b=M3GRvHpyQtR6sisnRKNOfitwrQZHI9jap++WyaMzhnXEzU2CZYrkjn1+G4zaBW9G4LwYff1eubdnzaSNuRZuUiXHFDm3Rlqhdt53UNhaZ+vdxiiALHX+hS6r9i892KssCNdjFN2MQNcZ1xXkauC5NfyMsMdSUXUWz8xFvx1vj90= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724657603; c=relaxed/simple; bh=VjPLqwW++1MDyV9TLLz3ZzvxP90qb3XnQT33yu8LNqo=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=BU4EveoSXGarFk3p3SNO49aDus2Xp96Noc9FiAO08M0lluz+pBsidgPAbXoGpq5E3vOWO2oGW7e/pxp4Apntqm1RVhr3JXtTMiTnLwVkIzacZQ1S3c2HUGVJo06DlDHNmW8NqDg9fXuaQg3V39r7uIKl2b6QgIDEBaCspqSZVoU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1724657602; x=1756193602; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=VjPLqwW++1MDyV9TLLz3ZzvxP90qb3XnQT33yu8LNqo=; b=JD077yDv7kGUZR0H9IR81UUrohTQw0WtxuDZW2h1UVeU9jR35H+XeVcz tzB27t3hYg/zPb9L47pGBHzsmQhv3+ilrpfhHXdjb0A3aMoYiqf4/RyZC K8n0Wqo/0gqZn1fk4Fw9Drn0rA4rojFaEvsgZFQxAPFeMlA1E8GYuY7We geC6GYpRaRT3L+kTQkgVS5hoUdNXCUBton7MC8t1zHOEhUHyYRyKbCNR6 aES/lMr8G5yiKk/R0dxvSTrjYK0vbr4gRaNbyJJ24eGkrcUo4jybG9TBD zN967EzJMlcXzs4NS0OIwRFZA4AaT1b2gO6kwu8RmDuTxuPtLveOltgEW Q==; X-CSE-ConnectionGUID: kKhtLIFSSCyicNQt3quYDA== X-CSE-MsgGUID: yY1apphMTiyN5oIhkJh0rQ== X-IronPort-AV: E=McAfee;i="6700,10204,11175"; a="33682716" X-IronPort-AV: E=Sophos;i="6.10,176,1719903600"; d="scan'208";a="33682716" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2024 00:33:21 -0700 X-CSE-ConnectionGUID: owAt2fh1QDecgli0NkuEuw== X-CSE-MsgGUID: CdywmASMRLyEhfFRQFGJcA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,176,1719903600"; d="scan'208";a="85609541" Received: from shliclel4217.sh.intel.com ([10.239.240.127]) by fmviesa002.fm.intel.com with ESMTP; 26 Aug 2024 00:33:19 -0700 From: liuhongt To: gcc-patches@gcc.gnu.org Cc: crazylht@gmail.com, hjl.tools@gmail.com Subject: [PATCH 1/2] Enhance cse_insn to handle all-zeros and all-ones for vector mode. Date: Mon, 26 Aug 2024 15:33:17 +0800 Message-Id: <20240826073318.2521204-1-hongtao.liu@intel.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 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, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Also try to handle redundant broadcasts when there's already a broadcast to a bigger mode with exactly the same component value. For broadcast, component mode needs to be the same. For all-zeros/ones, only need to check the bigger mode. Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,} and aarch64-linux-gnu{-m32,}. OK for trunk? gcc/ChangeLog: PR rtl-optimization/92080 * cse.cc (cse_insn): Handle all-ones/all-zeros, and vec_dup with variables. --- gcc/cse.cc | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/gcc/cse.cc b/gcc/cse.cc index 65794ac5f2c..baf90910b94 100644 --- a/gcc/cse.cc +++ b/gcc/cse.cc @@ -4870,6 +4870,50 @@ cse_insn (rtx_insn *insn) } } + /* Try to handle special const_vector with elt 0 or -1. + They can be represented with different modes, and can be cse. */ + if (src_const && src_related == 0 && CONST_VECTOR_P (src_const) + && (src_const == CONST0_RTX (mode) + || src_const == CONSTM1_RTX (mode)) + && GET_MODE_CLASS (mode) == MODE_VECTOR_INT) + { + machine_mode mode_iter; + + for (int l = 0; l != 2; l++) + { + FOR_EACH_MODE_IN_CLASS (mode_iter, MODE_VECTOR_INT) + { + if (maybe_lt (GET_MODE_SIZE (mode_iter), + GET_MODE_SIZE (mode))) + continue; + + rtx src_const_iter = (src_const == CONST0_RTX (mode) + ? CONST0_RTX (mode_iter) + : CONSTM1_RTX (mode_iter)); + + struct table_elt *const_elt + = lookup (src_const_iter, HASH (src_const_iter, mode_iter), + mode_iter); + + if (const_elt == 0) + continue; + + for (const_elt = const_elt->first_same_value; + const_elt; const_elt = const_elt->next_same_value) + if (REG_P (const_elt->exp)) + { + src_related = gen_lowpart (mode, const_elt->exp); + break; + } + + if (src_related != 0) + break; + } + if (src_related != 0) + break; + } + } + /* See if we have a CONST_INT that is already in a register in a wider mode. */ @@ -5041,6 +5085,41 @@ cse_insn (rtx_insn *insn) } } + /* Try to find something like (vec_dup:v16si (reg:c)) + for (vec_dup:v8si (reg:c)). */ + if (src_related == 0 + && VECTOR_MODE_P (mode) + && GET_CODE (src) == VEC_DUPLICATE) + { + poly_uint64 nunits = GET_MODE_NUNITS (GET_MODE (src)) * 2; + rtx inner_elt = XEXP (src, 0); + machine_mode result_mode; + struct table_elt *src_related_elt = NULL;; + while (related_vector_mode (mode, GET_MODE_INNER (mode), + nunits).exists (&result_mode)) + { + rtx vec_dup = gen_rtx_VEC_DUPLICATE (result_mode, inner_elt); + struct table_elt* tmp = lookup (vec_dup, HASH (vec_dup, result_mode), + result_mode); + if (tmp) + src_related_elt = tmp; + nunits *= 2; + } + + if (src_related_elt) + { + for (src_related_elt = src_related_elt->first_same_value; + src_related_elt; + src_related_elt = src_related_elt->next_same_value) + if (REG_P (src_related_elt->exp)) + { + src_related = gen_lowpart (mode, src_related_elt->exp); + break; + } + } + } + + if (src == src_folded) src_folded = 0;