From patchwork Wed May 15 10:05:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liuhongt X-Patchwork-Id: 1935517 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=bSO+E7u7; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4VfTQ465qBz1ymw for ; Wed, 15 May 2024 20:06:04 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 14451384AB44 for ; Wed, 15 May 2024 10:06:02 +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 [198.175.65.19]) by sourceware.org (Postfix) with ESMTPS id 472043858D33 for ; Wed, 15 May 2024 10:05:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 472043858D33 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 472043858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715767540; cv=none; b=O8JXMjGhXRR8KLKJlR8kOtaulfN1t7ZmCA7GUsW/zAaEVy5SOPXKV4f8H9uCYV5FH6BO7vsni3pe/e/yeE3VJVYCBdKchPtDWBhm3TQBK/waJpgSP1YaFIxkfTEKkvXwigdEhFl+MshzC0mhJRY0emGXdpJbfJ6IOmYKB5uirm4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715767540; c=relaxed/simple; bh=NtxpmEREfNMJgLq/JScNaBOj6lgoafCSm2EClTMwZek=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=YdQTdreqECfT8L77Iw8wXKiaAc4W7sdsFCNUabU3M6RLggMd9prrS6y/ILPiPeTJrIJyp8W/FC8PUosIbAr05pTbZAB6QEVOZVtQ+GCeDfj/MHvtIjTZLAfh1L+n3V5jNgBG0vFuaXKiaObZEwKeZWpi4fLuKgvtMnwfRnkY0RU= 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=1715767539; x=1747303539; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=NtxpmEREfNMJgLq/JScNaBOj6lgoafCSm2EClTMwZek=; b=bSO+E7u7/L5IzoP/qFfjELF2rzRD+LON5EovlTxs6cBcL045e9Zsbea7 KonqBsLE7QoYER270PWzHTrzMEOmGhbyklm5CCeKFnbmqU1k/gLwM/eGg 5zhnJMKCloFNkrunIiw2X6tiBYa4lzzCB+HUNLQcrYvbh1PcII5f4fBUo iJ8dHkBZNMBCtR0uye510sqRjbCJGS3ptSEKN0ZS4pLKx7e5H89uPt5+K ODUmkoLHWRhRB2gbr93xOUuAchJzpbV0dWizTyJaePIlIeAABiKEZEypI xJ8d+N3Mee3axgcLnBcS1eXJZJbJ/vxL/lcxXtj0QFMxIR8ttKXw2mees w==; X-CSE-ConnectionGUID: SYi2qTTcTjCyzzp6jrnqpw== X-CSE-MsgGUID: f74+zCnqQhy/aP7W60b3ZQ== X-IronPort-AV: E=McAfee;i="6600,9927,11073"; a="11661061" X-IronPort-AV: E=Sophos;i="6.08,161,1712646000"; d="scan'208";a="11661061" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 May 2024 03:05:37 -0700 X-CSE-ConnectionGUID: QOetrtchQ5m0TXLEFWmO8g== X-CSE-MsgGUID: Z9TjOG/aRU+3BV0FxMMWxA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,161,1712646000"; d="scan'208";a="31093800" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by fmviesa010.fm.intel.com with ESMTP; 15 May 2024 03:05:36 -0700 Received: from shliclel4217.sh.intel.com (shliclel4217.sh.intel.com [10.239.240.127]) by shvmail03.sh.intel.com (Postfix) with ESMTP id E86971007349; Wed, 15 May 2024 18:05:34 +0800 (CST) From: liuhongt To: gcc-patches@gcc.gnu.org Cc: ubizjak@gmail.com Subject: [PATCH] [x86] Set d.one_operand_p to true when TARGET_SSSE3 in ix86_expand_vecop_qihi_partial. Date: Wed, 15 May 2024 18:05:34 +0800 Message-Id: <20240515100534.4120288-1-hongtao.liu@intel.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 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 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 pshufb is available under TARGET_SSSE3, so ix86_expand_vec_perm_const_1 must return true when TARGET_SSSE3. w/o TARGET_SSSE3, if we set one_operand_p to true, ix86_expand_vec_perm_const_1 could return false. With the patch under -march=x86-64-v2 v8qi foo (v8qi a) { return a >> 5; } < pmovsxbw %xmm0, %xmm0 < psraw $5, %xmm0 < pshufb .LC0(%rip), %xmm0 --- > movdqa %xmm0, %xmm1 > pcmpeqd %xmm0, %xmm0 > pmovsxbw %xmm1, %xmm1 > psrlw $8, %xmm0 > psraw $5, %xmm1 > pand %xmm1, %xmm0 > packuswb %xmm0, %xmm0 Although there's a memory load from constant pool, but it should be better when it's inside a loop. The load from constant pool can be hoist out. it's 1 instruction vs 4 instructions. < pshufb .LC0(%rip), %xmm0 vs. > pcmpeqd %xmm0, %xmm0 > psrlw $8, %xmm0 > pand %xmm1, %xmm0 > packuswb %xmm0, %xmm0 Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}. Ok for trunk. gcc/ChangeLog: PR target/114514 * config/i386/i386-expand.cc (ix86_expand_vecop_qihi_partial): Set d.one_operand_p to true when TARGET_SSSE3. gcc/testsuite/ChangeLog: * gcc.target/i386/pr114514-shufb.c: New test. --- gcc/config/i386/i386-expand.cc | 2 +- .../gcc.target/i386/pr114514-shufb.c | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr114514-shufb.c diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc index ab6631f51e3..ae2e9ab4e05 100644 --- a/gcc/config/i386/i386-expand.cc +++ b/gcc/config/i386/i386-expand.cc @@ -24394,7 +24394,7 @@ ix86_expand_vecop_qihi_partial (enum rtx_code code, rtx dest, rtx op1, rtx op2) d.op0 = d.op1 = qres; d.vmode = V16QImode; d.nelt = 16; - d.one_operand_p = false; + d.one_operand_p = TARGET_SSSE3; d.testing_p = false; for (i = 0; i < d.nelt; ++i) diff --git a/gcc/testsuite/gcc.target/i386/pr114514-shufb.c b/gcc/testsuite/gcc.target/i386/pr114514-shufb.c new file mode 100644 index 00000000000..71fdc9d8daf --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr114514-shufb.c @@ -0,0 +1,35 @@ +/* { dg-do compile } */ +/* { dg-options "-msse4.1 -O2 -mno-avx512f" } */ +/* { dg-final { scan-assembler-not "packuswb" } } */ +/* { dg-final { scan-assembler-times "pshufb" 4 { target { ! ia32 } } } } */ +/* { dg-final { scan-assembler-times "pshufb" 6 { target ia32 } } } */ + +typedef unsigned char v8uqi __attribute__((vector_size(8))); +typedef char v8qi __attribute__((vector_size(8))); +typedef unsigned char v4uqi __attribute__((vector_size(4))); +typedef char v4qi __attribute__((vector_size(4))); + +v8qi +foo (v8qi a) +{ + return a >> 5; +} + +v8uqi +foo1 (v8uqi a) +{ + return a >> 5; +} + +v4qi +foo2 (v4qi a) +{ + return a >> 5; +} + +v4uqi +foo3 (v4uqi a) +{ + return a >> 5; +} +