From patchwork Tue Aug 24 08:55:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liuhongt X-Patchwork-Id: 1520154 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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: 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=YYUvcn9c; 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Gv2yZ5FLvz9sW5 for ; Tue, 24 Aug 2021 18:56:06 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5AF2C3857C53 for ; Tue, 24 Aug 2021 08:56:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5AF2C3857C53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1629795364; bh=cd4cMbIXBANdX57LYd7XQutBlRxmlwRThbEi03Hr0lc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=YYUvcn9cnTG6jfNmn19XGVCS6ZuJLahiBZwlyvIO5iW2FfD5thf/CP2ls0mFpS3aj TpncoiXj5C6e5vCvSdQfb72PZOZWwiNe81BGGI6Kyk6flHRbhndaC2JhSaUPn5w93b VNy5szXXT7CW4ZSxPVIdIbznysMDHk9PMeiRJz6k= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by sourceware.org (Postfix) with ESMTPS id 575093858C2C for ; Tue, 24 Aug 2021 08:55:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 575093858C2C X-IronPort-AV: E=McAfee;i="6200,9189,10085"; a="302851366" X-IronPort-AV: E=Sophos;i="5.84,346,1620716400"; d="scan'208";a="302851366" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Aug 2021 01:55:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,346,1620716400"; d="scan'208";a="473425765" Received: from scymds01.sc.intel.com ([10.148.94.138]) by orsmga008.jf.intel.com with ESMTP; 24 Aug 2021 01:55:33 -0700 Received: from shliclel219.sh.intel.com (shliclel219.sh.intel.com [10.239.236.219]) by scymds01.sc.intel.com with ESMTP id 17O8tVKK023555; Tue, 24 Aug 2021 01:55:31 -0700 To: gcc-patches@gcc.gnu.org Subject: [PATCH] Change illegitimate constant into memref of constant pool in change_zero_ext. Date: Tue, 24 Aug 2021 16:55:30 +0800 Message-Id: <20210824085530.356808-1-hongtao.liu@intel.com> X-Mailer: git-send-email 2.27.0 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, 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: segher@kernel.crashing.org Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi: This patch extend change_zero_ext to change illegitimate constant into constant pool, this will enable simplification of below: Trying 5 -> 7: 5: r85:V4SF=[`*.LC0'] REG_EQUAL const_vector 7: r84:V4SF=vec_select(vec_concat(r85:V4SF,r85:V4SF),parallel) REG_DEAD r85:V4SF REG_EQUAL const_vector Failed to match this instruction: (set (reg:V4SF 84) (const_vector:V4SF [ (const_double:SF 3.0e+0 [0x0.cp+2]) (const_double:SF 2.0e+0 [0x0.8p+2]) (const_double:SF 4.0e+0 [0x0.8p+3]) (const_double:SF 1.0e+0 [0x0.8p+1]) ])) (insn 5 2 7 2 (set (reg:V4SF 85) (mem/u/c:V4SF (symbol_ref/u:DI ("*.LC0") [flags 0x2]) [0 S16 A128])) 1600 {movv4sf_internal} (expr_list:REG_EQUAL (const_vector:V4SF [ (const_double:SF 4.0e+0 [0x0.8p+3]) (const_double:SF 3.0e+0 [0x0.cp+2]) (const_double:SF 2.0e+0 [0x0.8p+2]) (const_double:SF 1.0e+0 [0x0.8p+1]) ]) (nil))) (insn 7 5 11 2 (set (reg:V4SF 84) (vec_select:V4SF (vec_concat:V8SF (reg:V4SF 85) (reg:V4SF 85)) (parallel [ (const_int 1 [0x1]) (const_int 2 [0x2]) (const_int 4 [0x4]) (const_int 7 [0x7]) ]))) 3015 {sse_shufps_v4sf} (expr_list:REG_DEAD (reg:V4SF 85) (expr_list:REG_EQUAL (const_vector:V4SF [ (const_double:SF 3.0e+0 [0x0.cp+2]) (const_double:SF 2.0e+0 [0x0.8p+2]) (const_double:SF 4.0e+0 [0x0.8p+3]) (const_double:SF 1.0e+0 [0x0.8p+1]) ]) (nil)))) Bootstrapped and regtested on x86_64-linux-gnu{-m32,}. Ok for trunk? gcc/ChangeLog: PR rtl-optimization/43147 * combine.c (recog_for_combine_1): Adjust comments of .. (change_zero_ext):.. this, and extend to change illegitimate constant into constant pool. gcc/testsuite/ChangeLog: PR rtl-optimization/43147 * gcc.target/i386/pr43147.c: New test. * gcc.target/i386/pr22076.c: Adjust testcase. --- gcc/combine.c | 20 +++++++++++++++++++- gcc/testsuite/gcc.target/i386/pr22076.c | 4 ++-- gcc/testsuite/gcc.target/i386/pr43147.c | 15 +++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr43147.c diff --git a/gcc/combine.c b/gcc/combine.c index cb5fa401fcb..0b2afdf45af 100644 --- a/gcc/combine.c +++ b/gcc/combine.c @@ -11404,7 +11404,8 @@ recog_for_combine_1 (rtx *pnewpat, rtx_insn *insn, rtx *pnotes) /* Change every ZERO_EXTRACT and ZERO_EXTEND of a SUBREG that can be expressed as an AND and maybe an LSHIFTRT, to that formulation. - Return whether anything was so changed. */ + Return whether anything was so changed. + Also change illegitimate constant into memref of constant pool. */ static bool change_zero_ext (rtx pat) @@ -11417,6 +11418,23 @@ change_zero_ext (rtx pat) { rtx x = **iter; scalar_int_mode mode, inner_mode; + machine_mode const_mode = GET_MODE (x); + + /* Change illegitimate constant into memref of constant pool. */ + if (CONSTANT_P (x) + && !const_vec_duplicate_p (x) + && const_mode != BLKmode + && GET_CODE (x) != HIGH + && GET_MODE_SIZE (const_mode).is_constant () + && !targetm.legitimate_constant_p (const_mode, x) + && !targetm.cannot_force_const_mem (const_mode, x)) + { + x = force_const_mem (GET_MODE (x), x); + SUBST (**iter, x); + changed = true; + continue; + } + if (!is_a (GET_MODE (x), &mode)) continue; int size; diff --git a/gcc/testsuite/gcc.target/i386/pr22076.c b/gcc/testsuite/gcc.target/i386/pr22076.c index 427ffcd4920..866c387280f 100644 --- a/gcc/testsuite/gcc.target/i386/pr22076.c +++ b/gcc/testsuite/gcc.target/i386/pr22076.c @@ -15,5 +15,5 @@ void test () x = _mm_add_pi8 (mm0, mm1); } -/* { dg-final { scan-assembler-times "movq" 2 } } */ -/* { dg-final { scan-assembler-not "movl" { target nonpic } } } */ +/* { dg-final { scan-assembler-times "movq" 2 { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler-times "movl" 4 { target ia32 } } } */ diff --git a/gcc/testsuite/gcc.target/i386/pr43147.c b/gcc/testsuite/gcc.target/i386/pr43147.c new file mode 100644 index 00000000000..3c30f917c06 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr43147.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -msse2" } */ +/* { dg-final { scan-assembler "movaps" } } */ +/* { dg-final { scan-assembler-not "shufps" } } */ + +#include + +__m128 +foo (void) +{ + __m128 m = _mm_set_ps(1.0f, 2.0f, 3.0f, 4.0f); + m = _mm_shuffle_ps(m, m, 0xC9); + m = _mm_shuffle_ps(m, m, 0x2D); + return m; +}