From patchwork Wed Nov 29 09:06:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liuhongt X-Patchwork-Id: 171169 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a5a7:0:b0:403:3b70:6f57 with SMTP id d7csp210658vqn; Wed, 29 Nov 2023 01:07:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IEbUhRL44tYcoEAgPZPCH2m9R59bTm7fIsKYq6kxq2PukquRmd4zk4B3gp02S1W51S3OXJs X-Received: by 2002:ad4:4207:0:b0:67a:2940:6f45 with SMTP id k7-20020ad44207000000b0067a29406f45mr11290945qvp.21.1701248846535; Wed, 29 Nov 2023 01:07:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701248846; cv=pass; d=google.com; s=arc-20160816; b=Ptdxk2eoJ7juK5L1nQiAxzIEdgwjyeTJbBNGsmj4iClxAFokCwgudv0HFBao9IQ+9H GbEHUUVmIbUaeCJGnWs0N0Jw/B4xv6Y+r2JOihS2NliB8s2bwm6mWsaCDZFUigpMdic7 Iwrgye67LCm/t0o4dh7daCGtTb1HKLRibEFc15PiWQEFSHfakXSNZTLdce+kd5/BAPg5 CmmXgMJ8dzKAmtDL/s9egTdcxEg7DNezGFbT4JBRi8oAIhtT0D6L+4giIa1EXUpkc3Cc r2xVqRxAYzajY3QbGhkCMsBGViXbapeCD0q3ntqjrxI8qCr1r7PI7cKURi7bz/3Hg/Tb FxdA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=cEFeIKqpzvpjLGV2fgqunt2RA5m7OkU/YCI54yRYR/Q=; fh=ChXOctppJn0KECDRINafwUY5xHRufGHaa0Ju9pddrcQ=; b=gvktqbGsW7umAaR2LzGX8SN2t2anxgPFb9CRMOFI2eIiKLls0R3oMQriwYsmqUr+ln P4M7fvgMq+sZ2t86sS4C1GrtlZImJpDb7NYCMls2B7+um4UcyK7N5mpXhAEaAvptrWaf Y5jouYV2jTm+r0e6pIftM8nELoKfTs5XqBz2dt39+9HR7Md0VHyHY6GYSQfglr388Vy+ ayUSWBQA4bxq8CtuHx7RZOuOHOQp/jWY+dN5EGb3+CkG3GY4USX9JkUcEutPXnGTeYzJ FYCnDtf9hTk5fixLU/d45JdhjMYjKETph7os1h0nT8PKCE7QVQ9ouIcdL0mUwKzROmY2 IGkQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=e7kvHnJk; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id e2-20020a0562141d0200b0067a1bd19fd8si12013549qvd.77.2023.11.29.01.07.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 01:07:26 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=e7kvHnJk; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4FB1A385C6D4 for ; Wed, 29 Nov 2023 09:07:26 +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 [134.134.136.24]) by sourceware.org (Postfix) with ESMTPS id ED7F23856951 for ; Wed, 29 Nov 2023 09:06:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ED7F23856951 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 ED7F23856951 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=134.134.136.24 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701248814; cv=none; b=klGxnvJ3ufvKNEx7hug3vGGVuv/yP4IAd/mKR94HmYgVt1V4jaIwhKS7bwpj0K85zgqcw1JbsqecADlqXoUewixzKFqzGQMJO2RLCa9gYUnqfn5YRBslUaMAAF2SOu8wHz61t0qp7Pxtiq4TP+4v/g94dkF+3A6kblkWzxwW108= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701248814; c=relaxed/simple; bh=7hWzD+4gi57gO50zkAE1BmZwC8G2kaxSAlOikeS2CqE=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=JC8wZI/dmm0JAzDYo6TEmPj/KnEHQfTLloZ/XtQATPge22MxC032lGE5v3ki/wuWcx5/hvKBb6GMVcXMcYGCSqF+dXlbZDQWyAKd/VuCdYozv8oMqPiI9YBPe52BNF8cyMUx9LtA9kfa/+VEXnVxIejZ7AOrUdqQVptR20ipRpA= 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=1701248812; x=1732784812; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=7hWzD+4gi57gO50zkAE1BmZwC8G2kaxSAlOikeS2CqE=; b=e7kvHnJkvNC0IFmrikpRjN5JTPJPwTQQiwyBkSRjmBjdUDAzeFtOVb+b n7ZXz6Ua4efO7ApCt9uwuIvpCxn94+xq5XKF1jDfUdtmcPl3W2MGvoGq7 s9ZRGQbVjb2tXjxkek9QWceJjILpVxg2PwXed39mrQAu8GJ9oZS3XZS1F fe4PKBAv5SVcomgbZ4TvnCk0fwxugStJd21extEFaFO//Ats9Y/mnIOmO owlXPdPhZpd28yJvMxF+ZsBXCqVTpGWFWsP/QkHaGMFQ8fD5GjUcnjC2o aT6IefChsO9/V/fzuS9czygaV8JzjCA5zl9HGTmScKDL/+JO0IUX5rdE6 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10908"; a="395945952" X-IronPort-AV: E=Sophos;i="6.04,235,1695711600"; d="scan'208";a="395945952" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Nov 2023 01:06:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10908"; a="768830751" X-IronPort-AV: E=Sophos;i="6.04,235,1695711600"; d="scan'208";a="768830751" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by orsmga002.jf.intel.com with ESMTP; 29 Nov 2023 01:06:48 -0800 Received: from shliclel4217.sh.intel.com (shliclel4217.sh.intel.com [10.239.240.127]) by shvmail03.sh.intel.com (Postfix) with ESMTP id B43A01005664; Wed, 29 Nov 2023 17:06:47 +0800 (CST) From: liuhongt To: gcc-patches@gcc.gnu.org Cc: crazylht@gmail.com, hjl.tools@gmail.com Subject: [PATCH] Use vec_extact_lo instead of subreg in reduc__scal_m. Date: Wed, 29 Nov 2023 17:06:47 +0800 Message-Id: <20231129090647.2796938-1-hongtao.liu@intel.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783888710515702285 X-GMAIL-MSGID: 1783888710515702285 Loop vectorizer will use vec_perm to select lower part of a vector, there could be some redundancy when using subreg in reduc__scal_m, because rtl cse can't figure out vec_select lower part is just subreg. I'm trying to canonicalize vec_select to subreg like aarch64 did, but there're so many regressions, some are easy to fix, some requires middle-end adjustment. So for simplicity, the patch use vec_select instead of subreg in reduc__scal_m. Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}. Ready push to trunk. gcc/ChangeLog: * config/i386/sse.md: (reduc_plus_scal_): Use vec_extract_lo instead of subreg. (reduc__scal_): Ditto. (reduc__scal_): Ditto. (reduc__scal_): Ditto. (reduc__scal_): Ditto. --- gcc/config/i386/sse.md | 47 +++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md index 4f511693e3f..5e0e0e9e51f 100644 --- a/gcc/config/i386/sse.md +++ b/gcc/config/i386/sse.md @@ -3480,11 +3480,12 @@ (define_expand "reduc_plus_scal_" "" { rtx tmp = gen_reg_rtx (mode); - emit_insn (gen_vec_extract_hi_ (tmp, operands[1])); rtx tmp2 = gen_reg_rtx (mode); - rtx tmp3 = gen_lowpart (mode, operands[1]); - emit_insn (gen_add3 (tmp2, tmp, tmp3)); - emit_insn (gen_reduc_plus_scal_ (operands[0], tmp2)); + rtx tmp3 = gen_reg_rtx (mode); + emit_insn (gen_vec_extract_hi_ (tmp, operands[1])); + emit_insn (gen_vec_extract_lo_ (tmp2, operands[1])); + emit_insn (gen_add3 (tmp3, tmp, tmp2)); + emit_insn (gen_reduc_plus_scal_ (operands[0], tmp3)); DONE; }) @@ -3528,11 +3529,12 @@ (define_expand "reduc__scal_" "" { rtx tmp = gen_reg_rtx (mode); - emit_insn (gen_vec_extract_hi_ (tmp, operands[1])); rtx tmp2 = gen_reg_rtx (mode); - emit_insn (gen_3 - (tmp2, tmp, gen_lowpart (mode, operands[1]))); - emit_insn (gen_reduc__scal_ (operands[0], tmp2)); + rtx tmp3 = gen_reg_rtx (mode); + emit_insn (gen_vec_extract_hi_ (tmp, operands[1])); + emit_insn (gen_vec_extract_lo_ (tmp2, operands[1])); + emit_insn (gen_3 (tmp3, tmp, tmp2)); + emit_insn (gen_reduc__scal_ (operands[0], tmp3)); DONE; }) @@ -3543,11 +3545,12 @@ (define_expand "reduc__scal_" "TARGET_AVX512F" { rtx tmp = gen_reg_rtx (mode); - emit_insn (gen_vec_extract_hi_ (tmp, operands[1])); rtx tmp2 = gen_reg_rtx (mode); - emit_insn (gen_3 - (tmp2, tmp, gen_lowpart (mode, operands[1]))); - emit_insn (gen_reduc__scal_ (operands[0], tmp2)); + rtx tmp3 = gen_reg_rtx (mode); + emit_insn (gen_vec_extract_hi_ (tmp, operands[1])); + emit_insn (gen_vec_extract_lo_ (tmp2, operands[1])); + emit_insn (gen_3 (tmp3, tmp, tmp2)); + emit_insn (gen_reduc__scal_ (operands[0], tmp3)); DONE; }) @@ -3558,14 +3561,15 @@ (define_expand "reduc__scal_" "TARGET_AVX2" { rtx tmp = gen_reg_rtx (mode); - emit_insn (gen_vec_extract_hi_ (tmp, operands[1])); rtx tmp2 = gen_reg_rtx (mode); - emit_insn (gen_3 - (tmp2, tmp, gen_lowpart (mode, operands[1]))); rtx tmp3 = gen_reg_rtx (mode); - ix86_expand_reduc (gen_3, tmp3, tmp2); + emit_insn (gen_vec_extract_hi_ (tmp, operands[1])); + emit_insn (gen_vec_extract_lo_ (tmp2, operands[1])); + emit_insn (gen_3 (tmp3, tmp, tmp2)); + rtx tmp4 = gen_reg_rtx (mode); + ix86_expand_reduc (gen_3, tmp4, tmp3); emit_insn (gen_vec_extract - (operands[0], tmp3, const0_rtx)); + (operands[0], tmp4, const0_rtx)); DONE; }) @@ -3637,11 +3641,12 @@ (define_expand "reduc__scal_" "" { rtx tmp = gen_reg_rtx (mode); - emit_insn (gen_vec_extract_hi_ (tmp, operands[1])); rtx tmp2 = gen_reg_rtx (mode); - rtx tmp3 = gen_lowpart (mode, operands[1]); - emit_insn (gen_3 (tmp2, tmp, tmp3)); - emit_insn (gen_reduc__scal_ (operands[0], tmp2)); + rtx tmp3 = gen_reg_rtx (mode); + emit_insn (gen_vec_extract_hi_ (tmp, operands[1])); + emit_insn (gen_vec_extract_lo_ (tmp2, operands[1])); + emit_insn (gen_3 (tmp3, tmp, tmp2)); + emit_insn (gen_reduc__scal_ (operands[0], tmp3)); DONE; })