From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id 350573858D35 for ; Fri, 16 Jun 2023 16:27:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 350573858D35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nextmovesoftware.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=ZNwwxWztiuPTg24YzIICM+D2lgmuzhj+ZupuBlScuD0=; b=pOusBlxnnMBYMzddXuwzI2jy03 JxA8W5yDqc/asEz4AXpZgAB32USrjMN1ZXcCPE9TLPmrteKTS56dc3cTta3b1pEixHTAup1xe53SQ 1AWAfIp91yWDu+/a7p0o1DqhF/upYVoiR8Umy0F/YsH1lOZn5n/XeHRl9MGQywQtjY6K1r3ypM7p1 fM/g8z6aPTdWxpYRSRRfkFWqS4jfcegLWpd8ARU7dYGVNEkQ4fMcW+nQzrHIz4hJM8B/M/AKmT7sE RfckdDLgmpK9MkfFDh+EJi8vYruoxmrvkm6yO5tffQUcfSvJ8EXavKJ5LCt1x0uw7WCBqPRvJ/4go SHRtYcLA==; Received: from [185.62.158.67] (port=54978 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1qACIB-0004DF-1c; Fri, 16 Jun 2023 12:27:19 -0400 From: "Roger Sayle" To: Cc: "'Uros Bizjak'" Subject: [x86_64 PATCH] Two minor tweaks to ix86_expand_move. Date: Fri, 16 Jun 2023 17:27:17 +0100 Message-ID: <033d01d9a06f$6bdf2360$439d6a20$@nextmovesoftware.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_033E_01D9A077.CDA5D550" X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdmgbtkYnsc1QOcsRmWKvVgVb86o3g== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,SPF_HELO_NONE,SPF_PASS,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 List-Id: This is a multipart message in MIME format. ------=_NextPart_000_033E_01D9A077.CDA5D550 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit This patch splits out two (independent) minor changes to i386-expand.cc's ix86_expand_move from a larger patch, given that it's better to review and commit these independent pieces separately from a more complex patch. The first change is to test for CONST_WIDE_INT_P before calling ix86_convert_const_wide_int_to_broadcast. Whilst stepping through this function in gdb, I was surprised that the code was continually jumping into this function with operands that obviously weren't appropriate. The second change is to generalize the optimization for efficiently moving a TImode value to V1TImode (via V2DImode), to cover all 128-bit vector modes. Hence for the test case: typedef unsigned long uv2di __attribute__ ((__vector_size__ (16))); uv2di foo2(__int128 x) { return (uv2di)x; } we'd previously move via memory with: foo2: movq %rdi, -24(%rsp) movq %rsi, -16(%rsp) movdqa -24(%rsp), %xmm0 ret with this patch we now generate with -O2 (the same as V1TImode): foo2: movq %rdi, %xmm0 movq %rsi, %xmm1 punpcklqdq %xmm1, %xmm0 ret and with -O2 -msse4 the even better: foo2: movq %rdi, %xmm0 pinsrq $1, %rsi, %xmm0 ret The new test case is unimaginatively called sse2-v1ti-mov-2.c given the original test case just for V1TI mode was called sse2-v1ti-mov-1.c. This patch has been tested on x86_64-pc-linux-gnu with make bootstrap and make -k check, both with and without --target_board=unix{-m32} with no new failures. Ok for mainline? 2023-06-16 Roger Sayle gcc/ChangeLog * config/i386/i386-expand.cc (ix86_expand_move): Check that OP1 is CONST_WIDE_INT_P before calling ix86_convert_wide_int_to_broadcast. Generalize special case for converting TImode to V1TImode to handle all 128-bit vector conversions. gcc/testsuite/ChangeLog * gcc.target/i386/sse2-v1ti-mov-2.c: New test case. Thanks in advance, Roger -- ------=_NextPart_000_033E_01D9A077.CDA5D550 Content-Type: text/plain; name="patchvm.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="patchvm.txt" diff --git a/gcc/config/i386/i386-expand.cc = b/gcc/config/i386/i386-expand.cc=0A= index def060a..6a28b67 100644=0A= --- a/gcc/config/i386/i386-expand.cc=0A= +++ b/gcc/config/i386/i386-expand.cc=0A= @@ -521,7 +521,8 @@ ix86_expand_move (machine_mode mode, rtx operands[])=0A= return;=0A= }=0A= }=0A= - else if (GET_MODE_SIZE (mode) >=3D 16)=0A= + else if (CONST_WIDE_INT_P (op1)=0A= + && GET_MODE_SIZE (mode) >=3D 16)=0A= {=0A= rtx tmp =3D ix86_convert_const_wide_int_to_broadcast=0A= (GET_MODE (op0), op1);=0A= @@ -696,8 +697,9 @@ ix86_expand_vector_move (machine_mode mode, rtx = operands[])=0A= return;=0A= }=0A= =0A= - /* Special case TImode to V1TImode conversions, via V2DI. */=0A= - if (mode =3D=3D V1TImode=0A= + /* Special case TImode to 128-bit vector conversions via V2DI. */=0A= + if (VECTOR_MODE_P (mode)=0A= + && GET_MODE_SIZE (mode) =3D=3D 16=0A= && SUBREG_P (op1)=0A= && GET_MODE (SUBREG_REG (op1)) =3D=3D TImode=0A= && TARGET_64BIT && TARGET_SSE=0A= @@ -709,7 +711,7 @@ ix86_expand_vector_move (machine_mode mode, rtx = operands[])=0A= emit_move_insn (lo, gen_lowpart (DImode, SUBREG_REG (op1)));=0A= emit_move_insn (hi, gen_highpart (DImode, SUBREG_REG (op1)));=0A= emit_insn (gen_vec_concatv2di (tmp, lo, hi));=0A= - emit_move_insn (op0, gen_lowpart (V1TImode, tmp));=0A= + emit_move_insn (op0, gen_lowpart (mode, tmp));=0A= return;=0A= }=0A= =0A= diff --git a/gcc/testsuite/gcc.target/i386/sse2-v1ti-mov-2.c = b/gcc/testsuite/gcc.target/i386/sse2-v1ti-mov-2.c=0A= new file mode 100644=0A= index 0000000..7e89085=0A= --- /dev/null=0A= +++ b/gcc/testsuite/gcc.target/i386/sse2-v1ti-mov-2.c=0A= @@ -0,0 +1,16 @@=0A= +/* { dg-do compile { target int128 } } */=0A= +/* { dg-options "-O2 -msse2" } */=0A= +=0A= +typedef unsigned __int128 uv1ti __attribute__ ((__vector_size__ (16)));=0A= +typedef unsigned long uv2di __attribute__ ((__vector_size__ (16)));=0A= +typedef unsigned int uv4si __attribute__ ((__vector_size__ (16)));=0A= +typedef unsigned short uv8hi __attribute__ ((__vector_size__ (16)));=0A= +typedef unsigned char uv16qi __attribute__ ((__vector_size__ (16)));=0A= +=0A= +uv1ti foo1(__int128 x) { return (uv1ti)x; }=0A= +uv2di foo2(__int128 x) { return (uv2di)x; }=0A= +uv4si foo4(__int128 x) { return (uv4si)x; }=0A= +uv8hi foo8(__int128 x) { return (uv8hi)x; }=0A= +uv16qi foo16(__int128 x) { return (uv16qi)x; }=0A= +=0A= +/* { dg-final { scan-assembler-not "%\[er\]sp" } } */=0A= ------=_NextPart_000_033E_01D9A077.CDA5D550--