From: Jan Beulich <jbeulich@suse.com>
To: Binutils <binutils@sourceware.org>
Cc: "H.J. Lu" <hjl.tools@gmail.com>
Subject: [PATCH 3/4] x86: optimize 128-bit VPBROADCASTQ to VPUNPCKLQDQ
Date: Fri, 16 Jun 2023 09:31:41 +0200 [thread overview]
Message-ID: <3e1b884e-7312-8546-ebdc-ac513a199858@suse.com> (raw)
In-Reply-To: <bbc351cd-fa35-a3b7-8e2b-9d2edc4ab379@suse.com>
The alternative is 1 byte shorter when the source is %xmm0-7, as a
2-byte VEX prefix can then be used.
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -4620,6 +4620,33 @@ optimize_encoding (void)
i.op[1].regs = i.op[0].regs;
}
}
+ else if (optimize_for_space
+ && i.tm.base_opcode == 0x59
+ && i.tm.opcode_space == SPACE_0F38
+ && i.operands == i.reg_operands
+ && i.tm.opcode_modifier.vex
+ && !(i.op[0].regs->reg_flags & RegRex)
+ && i.op[0].regs->reg_type.bitfield.xmmword
+ && i.vec_encoding != vex_encoding_vex3)
+ {
+ /* Optimize: -Os:
+ vpbroadcastq %xmmN, %xmmM -> vpunpcklqdq %xmmN, %xmmN, %xmmM (N < 8)
+ */
+ i.tm.opcode_space = SPACE_0F;
+ i.tm.base_opcode = 0x6c;
+ i.tm.opcode_modifier.vexvvvv = 1;
+
+ ++i.operands;
+ ++i.reg_operands;
+ ++i.tm.operands;
+
+ i.op[2].regs = i.op[0].regs;
+ i.types[2] = i.types[0];
+ i.flags[2] = i.flags[0];
+ i.tm.operand_types[2] = i.tm.operand_types[0];
+
+ swap_2_operands (1, 2);
+ }
}
/* Return non-zero for load instruction. */
--- a/gas/testsuite/gas/i386/optimize-2.d
+++ b/gas/testsuite/gas/i386/optimize-2.d
@@ -164,4 +164,5 @@ Disassembly of section .text:
+[a-f0-9]+: 66 .* pcmpeqd %xmm2,%xmm2
+[a-f0-9]+: c5 .* vpcmpeqd %xmm2,%xmm2,%xmm0
+[a-f0-9]+: c5 .* vpcmpeqd %ymm2,%ymm2,%ymm0
+ +[a-f0-9]+: c5 .* vpunpcklqdq %xmm2,%xmm2,%xmm0
#pass
--- a/gas/testsuite/gas/i386/optimize-2.s
+++ b/gas/testsuite/gas/i386/optimize-2.s
@@ -184,3 +184,5 @@ _start:
pcmpeqq %xmm2, %xmm2
vpcmpeqq %xmm2, %xmm2, %xmm0
vpcmpeqq %ymm2, %ymm2, %ymm0
+
+ vpbroadcastq %xmm2, %xmm0
--- a/gas/testsuite/gas/i386/optimize-2b.d
+++ b/gas/testsuite/gas/i386/optimize-2b.d
@@ -165,4 +165,5 @@ Disassembly of section .text:
+[a-f0-9]+: 66 .* pcmpeqq %xmm2,%xmm2
+[a-f0-9]+: c4 .* vpcmpeqq %xmm2,%xmm2,%xmm0
+[a-f0-9]+: c4 .* vpcmpeqq %ymm2,%ymm2,%ymm0
+ +[a-f0-9]+: c4 .* vpbroadcastq %xmm2,%xmm0
#pass
--- a/gas/testsuite/gas/i386/x86-64-optimize-3.d
+++ b/gas/testsuite/gas/i386/x86-64-optimize-3.d
@@ -205,4 +205,6 @@ Disassembly of section .text:
+[a-f0-9]+: 66 .* pcmpeqd %xmm12,%xmm12
+[a-f0-9]+: c4 .* vpcmpeqq %xmm12,%xmm12,%xmm0
+[a-f0-9]+: c4 .* vpcmpeqq %ymm12,%ymm12,%ymm0
+ +[a-f0-9]+: c5 .* vpunpcklqdq %xmm2,%xmm2,%xmm0
+ +[a-f0-9]+: c4 .* vpbroadcastq %xmm12,%xmm0
#pass
--- a/gas/testsuite/gas/i386/x86-64-optimize-3.s
+++ b/gas/testsuite/gas/i386/x86-64-optimize-3.s
@@ -229,3 +229,6 @@ _start:
pcmpeqq %xmm12, %xmm12
vpcmpeqq %xmm12, %xmm12, %xmm0
vpcmpeqq %ymm12, %ymm12, %ymm0
+
+ vpbroadcastq %xmm2, %xmm0
+ vpbroadcastq %xmm12, %xmm0
--- a/gas/testsuite/gas/i386/x86-64-optimize-3b.d
+++ b/gas/testsuite/gas/i386/x86-64-optimize-3b.d
@@ -206,4 +206,6 @@ Disassembly of section .text:
+[a-f0-9]+: 66 .* pcmpeqq %xmm12,%xmm12
+[a-f0-9]+: c4 .* vpcmpeqq %xmm12,%xmm12,%xmm0
+[a-f0-9]+: c4 .* vpcmpeqq %ymm12,%ymm12,%ymm0
+ +[a-f0-9]+: c4 .* vpbroadcastq %xmm2,%xmm0
+ +[a-f0-9]+: c4 .* vpbroadcastq %xmm12,%xmm0
#pass
--- a/opcodes/i386-opc.tbl
+++ b/opcodes/i386-opc.tbl
@@ -1734,7 +1734,7 @@ vbroadcastsd, 0x6619, AVX2, Modrm|Vex=2|
vbroadcastss, 0x6618, AVX2, Modrm|Vex|Space0F38|VexW=1|NoSuf, { RegXMM, RegXMM|RegYMM }
vpblendd, 0x6602, AVX2, Modrm|Vex|Space0F3A|VexVVVV|VexW0|CheckOperandSize|NoSuf, { Imm8|Imm8S, Unspecified|BaseIndex|RegXMM|RegYMM, RegXMM|RegYMM, RegXMM|RegYMM }
vpbroadcast<bw>, 0x6678 | <bw:opc>, AVX2, Modrm|Vex|Space0F38|VexW0|NoSuf, { <bw:elem>|Unspecified|BaseIndex|RegXMM, RegXMM|RegYMM }
-vpbroadcast<dq>, 0x6658 | <dq:opc>, AVX2, Modrm|Vex|Space0F38|VexW0|NoSuf, { <dq:elem>|Unspecified|BaseIndex|RegXMM, RegXMM|RegYMM }
+vpbroadcast<dq>, 0x6658 | <dq:opc>, AVX2, Modrm|Vex|Space0F38|VexW0|NoSuf|Optimize, { <dq:elem>|Unspecified|BaseIndex|RegXMM, RegXMM|RegYMM }
vperm2i128, 0x6646, AVX2, Modrm|Vex=2|Space0F3A|VexVVVV|VexW0|NoSuf, { Imm8|Imm8S, Unspecified|BaseIndex|RegYMM, RegYMM, RegYMM }
vpermd, 0x6636, AVX2, Modrm|Vex256|Space0F38|VexVVVV|VexW0|NoSuf, { Unspecified|BaseIndex|RegYMM, RegYMM, RegYMM }
vpermpd, 0x6601, AVX2, Modrm|Vex=2|Space0F3A|VexW1|NoSuf, { Imm8|Imm8S, Unspecified|BaseIndex|RegYMM, RegYMM }
next prev parent reply other threads:[~2023-06-16 7:31 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-16 7:29 [PATCH 0/4] x86: some more optimization plus a new pseudo insn form Jan Beulich
2023-06-16 7:30 ` [PATCH 1/4] x86: optimize pre-AVX512 {,V}PCMPEQQ with identical sources Jan Beulich
2023-06-16 7:31 ` [PATCH 2/4] x86: optimize pre-AVX512 {,V}PCMPGT* " Jan Beulich
2023-06-16 7:31 ` Jan Beulich [this message]
2023-06-16 7:32 ` [PATCH 4/4] x86: provide a 128-bit VBROADCASTSD pseudo Jan Beulich
2023-06-16 16:59 ` H.J. Lu
2023-06-19 7:20 ` Jan Beulich
2023-06-20 16:07 ` H.J. Lu
2023-06-21 9:01 ` Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3e1b884e-7312-8546-ebdc-ac513a199858@suse.com \
--to=jbeulich@suse.com \
--cc=binutils@sourceware.org \
--cc=hjl.tools@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).