From patchwork Fri May 17 01:38:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liuhongt X-Patchwork-Id: 1936268 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=Rt1tjzij; 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 4VgV3m670Qz20dJ for ; Fri, 17 May 2024 11:38:42 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CE534384AB6E for ; Fri, 17 May 2024 01:38:39 +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.12]) by sourceware.org (Postfix) with ESMTPS id DB2F63858D20 for ; Fri, 17 May 2024 01:38:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DB2F63858D20 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 DB2F63858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715909900; cv=none; b=JXNThPLIKrR7Jax87Iro5Z4O5o6CFFPI4YtzBtJVdhh664ENGt/UlmDrvONNCZpuFP4H3vYVLRUZrbZ4CUKjPkIR0e5FJ/12Dd0V6wgzfyz6sljHJdqofN3WNrvVNvXkeG12Si4MDCxcW8TZF8JACaBy8ymrt+UIiP4ylRWCGeY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715909900; c=relaxed/simple; bh=+U5BGrC4TrJ5813ga6HP11wxfIAKRP6fbZRJfm8K5+M=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=JmrN4mEBxMAA/Wa0OcYjkVNDh+VIVQd1rnl4X3e8drm1zOff1fRcfnjpQlmHKQgeVX1Q0zrp6FszZOsPpXeQB0h7YyftboFSoi3muBQCZMuugp1/9mKKu645n/ZaooZneQ3XgaXmduTBs0b00h9C673j8GaoWBCLO7Qds+sJOWA= 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=1715909898; x=1747445898; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=+U5BGrC4TrJ5813ga6HP11wxfIAKRP6fbZRJfm8K5+M=; b=Rt1tjzijAfhZzVAgjWgKwT2MSC4sebftB85vKjAVn2Pl6yVfq+cp95Ct z38Ma2fx45KTg/lrukXWOQSLgzHUZcDtgQRS1Ynf5rSmiF6dCWsxxd90X IZ32LJhDhfPrK4PQyKlJPqDy8G+rMpmpUV68cjDWINLlLtQQXgJ8XBb0l 1FRUVLg1sowzF82nm4bc0LI3IQZKqJwnEZqieXRFc5EBaAAMYA/L53pek 0D3PSuC9w45wpFo+bBRPr0CXWHTvxHUA/V6ZPo+txupHGFyr6+7ln+lGo TmLxrk3t40Dry3C2OoFpLIcajR45Aq28AE1222Vt+nBhUjttmT/YjnVjx w==; X-CSE-ConnectionGUID: ebSOiQXfTmqtKLn2lGj2tw== X-CSE-MsgGUID: Mb81BAowS4ujAKveODXbYA== X-IronPort-AV: E=McAfee;i="6600,9927,11074"; a="23469489" X-IronPort-AV: E=Sophos;i="6.08,166,1712646000"; d="scan'208";a="23469489" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 May 2024 18:38:16 -0700 X-CSE-ConnectionGUID: 4swZAkWeQIW1Y0cIItsK/w== X-CSE-MsgGUID: PF7N2rhqR9CYjTqY/unAzg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,166,1712646000"; d="scan'208";a="36421305" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by orviesa005.jf.intel.com with ESMTP; 16 May 2024 18:38:15 -0700 Received: from shliclel4217.sh.intel.com (shliclel4217.sh.intel.com [10.239.240.127]) by shvmail03.sh.intel.com (Postfix) with ESMTP id B58A810077DE; Fri, 17 May 2024 09:38:13 +0800 (CST) From: liuhongt To: gcc-patches@gcc.gnu.org Cc: crazylht@gmail.com, hjl.tools@gmail.com Subject: [PATCH] Use pblendw instead of pand to clear upper 16 bits. Date: Fri, 17 May 2024 09:38:13 +0800 Message-Id: <20240517013813.493642-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 For vec_pack_truncv8si/v4si w/o AVX512, (const_vector:v4si (const_int 0xffff) x4) is used as mask to clear upper 16 bits, but vpblendw with zero_vector can also be used, and zero vector is cheaper than (const_vector:v4si (const_int 0xffff) x4). Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}. Ready push to trunk. gcc/ChangeLog: PR target/114427 * config/i386/i386-expand.cc (expand_vec_perm_even_odd_pack): Use pblendw instead of pand to clear upper bits. gcc/testsuite/ChangeLog: * gcc.target/i386/pr114427.c: New test. --- gcc/config/i386/i386-expand.cc | 34 +++++++++++++++++++++--- gcc/testsuite/gcc.target/i386/pr114427.c | 18 +++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr114427.c diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc index 4e16aedc5c1..231e9321d81 100644 --- a/gcc/config/i386/i386-expand.cc +++ b/gcc/config/i386/i386-expand.cc @@ -22918,6 +22918,7 @@ expand_vec_perm_even_odd_pack (struct expand_vec_perm_d *d) { rtx op, dop0, dop1, t; unsigned i, odd, c, s, nelt = d->nelt; + int pblendw_i = 0; bool end_perm = false; machine_mode half_mode; rtx (*gen_and) (rtx, rtx, rtx); @@ -22939,6 +22940,7 @@ expand_vec_perm_even_odd_pack (struct expand_vec_perm_d *d) gen_and = gen_andv2si3; gen_pack = gen_mmx_packusdw; gen_shift = gen_lshrv2si3; + pblendw_i = 0x5; break; case E_V8HImode: /* Required for "pack". */ @@ -22950,6 +22952,7 @@ expand_vec_perm_even_odd_pack (struct expand_vec_perm_d *d) gen_and = gen_andv4si3; gen_pack = gen_sse4_1_packusdw; gen_shift = gen_lshrv4si3; + pblendw_i = 0x55; break; case E_V8QImode: /* No check as all instructions are SSE2. */ @@ -22978,6 +22981,7 @@ expand_vec_perm_even_odd_pack (struct expand_vec_perm_d *d) gen_and = gen_andv8si3; gen_pack = gen_avx2_packusdw; gen_shift = gen_lshrv8si3; + pblendw_i = 0x5555; end_perm = true; break; case E_V32QImode: @@ -23013,10 +23017,32 @@ expand_vec_perm_even_odd_pack (struct expand_vec_perm_d *d) dop1 = gen_reg_rtx (half_mode); if (odd == 0) { - t = gen_const_vec_duplicate (half_mode, GEN_INT (c)); - t = force_reg (half_mode, t); - emit_insn (gen_and (dop0, t, gen_lowpart (half_mode, d->op0))); - emit_insn (gen_and (dop1, t, gen_lowpart (half_mode, d->op1))); + /* Use pblendw since const_vector 0 should be cheaper than + const_vector 0xffff. */ + if (d->vmode == V4HImode + || d->vmode == E_V8HImode + || d->vmode == E_V16HImode) + { + rtx dop0_t = gen_reg_rtx (d->vmode); + rtx dop1_t = gen_reg_rtx (d->vmode); + t = gen_reg_rtx (d->vmode); + emit_move_insn (t, CONST0_RTX (d->vmode)); + + emit_move_insn (dop0_t, gen_rtx_VEC_MERGE (d->vmode, d->op0, t, + GEN_INT (pblendw_i))); + emit_move_insn (dop1_t, gen_rtx_VEC_MERGE (d->vmode, d->op1, t, + GEN_INT (pblendw_i))); + + emit_move_insn (dop0, gen_lowpart (half_mode, dop0_t)); + emit_move_insn (dop1, gen_lowpart (half_mode, dop1_t)); + } + else + { + t = gen_const_vec_duplicate (half_mode, GEN_INT (c)); + t = force_reg (half_mode, t); + emit_insn (gen_and (dop0, t, gen_lowpart (half_mode, d->op0))); + emit_insn (gen_and (dop1, t, gen_lowpart (half_mode, d->op1))); + } } else { diff --git a/gcc/testsuite/gcc.target/i386/pr114427.c b/gcc/testsuite/gcc.target/i386/pr114427.c new file mode 100644 index 00000000000..58b66db7fff --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr114427.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-march=x86-64-v3 -O2 -mno-avx512f" } */ +/* { dg-final { scan-assembler-not "vpand" } } */ +/* { dg-final { scan-assembler-not "65535" } } */ + +void +foo (int* a, short* __restrict b, int* c) +{ + for (int i = 0; i != 16; i++) + b[i] = c[i] + a[i]; +} + +void +foo1 (int* a, short* __restrict b, int* c) +{ + for (int i = 0; i != 8; i++) + b[i] = c[i] + a[i]; +}