From: "Roger Sayle" <roger@nextmovesoftware.com>
To: <gcc-patches@gcc.gnu.org>
Subject: [RFC] Workaround LRA reload issue with SUBREGs in SET_DEST.
Date: Sun, 18 Jun 2023 14:20:32 +0100 [thread overview]
Message-ID: <002001d9a1e7$aa0daac0$fe290040$@nextmovesoftware.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 3010 bytes --]
I was wondering whether I could ask a LRA/reload expert for their help with
a better fix with this issue.
For the testcase (from sse2-v1ti-mov-1.c):
typedef unsigned __int128 uv1ti __attribute__ ((__vector_size__ (16)));
uv1ti foo(__int128 x) { return (uv1ti)x; }
we currently generate (with -O2) the suboptimal:
movq %rdi, %xmm1
movq %rsi, %xmm2
punpcklqdq %xmm2, %xmm1
movdqa %xmm1, %xmm0
Notice that (due to register allocation) the result is calculated in
%xmm1 and in the final structure copied to the result %xmm0.
With the one line change (workaround) below, we generate the better
(optimal) sequence:
movq %rdi, %xmm0
movq %rsi, %xmm1
punpcklqdq %xmm1, %xmm0
The triggering event responsible for the current behaviour is that
combine merges the two instructions:
(insn 12 7 13 2 (set (reg:V2DI 88)
(vec_concat:V2DI (reg:DI 95)
(reg:DI 96))) "sse2-v1ti-mov-1.c":8:10 discrim 1 7238
{vec_concatv2di}
(expr_list:REG_DEAD (reg:DI 96)
(expr_list:REG_DEAD (reg:DI 95)
(nil))))
(insn 13 12 17 2 (set (reg:V1TI 82 [ <retval> ])
(subreg:V1TI (reg:V2DI 88) 0)) "sse2-v1ti-mov-1.c":8:10 discrim 1
1860 {movv1ti_internal}
(expr_list:REG_DEAD (reg:V2DI 88)
(nil)))
into the single instruction (with a SUBREG in the SET_DEST):
(insn 13 12 17 2 (set (subreg:V2DI (reg:V1TI 82 [ <retval> ]) 0)
(vec_concat:V2DI (reg:DI 95)
(reg:DI 96))) "sse2-v1ti-mov-1.c":8:10 discrim 1 7244
{vec_concatv2di}
(expr_list:REG_DEAD (reg:DI 95)
(expr_list:REG_DEAD (reg:DI 96)
(nil))))
Unfortunately, this form is challenging for lra/reload...
Choosing alt 4 in insn 13: (0) x (1) 0 (2) x {vec_concatv2di}
Creating newreg=98, assigning class SSE_REGS to r98
Creating newreg=99 from oldreg=96, assigning class SSE_REGS to r99
13: r98:V2DI=vec_concat(r98:V2DI#0,r99:DI)
REG_DEAD r96:DI
REG_DEAD r95:DI
Inserting insn reload before:
27: clobber r98:V2DI
28: r98:V2DI#0=r95:DI
30: r99:DI=r96:DI
Inserting insn reload after:
29: r82:V1TI#0=r98:V2DI
It's the clobber of r98 (insn 27) that's generated by the emit_clobber
at around line 1081 in match_reload from lra-constraints.cc that's critical,
causing r82 and r98 to occupy different registers/allocations. Is there
a way of preventing this clobber/conflict? Are V2DI and V1TI correctly
annotated as tieable to the same hard register.
This patch works by explicitly checking that the destination in
vec_concatv2di is a REG_P, i.e. not a SUBREG, and therefore preventing
the two instructions to be merged by combine. But clearly this is a
case where lra/reload could be doing better.
Thoughts?
2023-06-18 Roger Sayle <roger@nextmovesoftware.com>
gcc/ChangeLog
* config/i386/sse.md (vec_concatv2di): Require that the destination
is a REG_P (i.e. a pseudo or hard register, not a SUBREG).
Roger
--
[-- Attachment #2: patchvm2.txt --]
[-- Type: text/plain, Size: 429 bytes --]
diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index 70d7410..20a26a0 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -20060,7 +20060,7 @@
" 0, 0,x ,Yv,0,Yv,0,0,v")
(match_operand:DI 2 "nonimmediate_operand"
" rm,rm,rm,rm,x,Yv,x,m,m")))]
- "TARGET_SSE"
+ "TARGET_SSE && REG_P (operands[0])"
"@
pinsrq\t{$1, %2, %0|%0, %2, 1}
pinsrq\t{$1, %2, %0|%0, %2, 1}
reply other threads:[~2023-06-18 13:20 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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='002001d9a1e7$aa0daac0$fe290040$@nextmovesoftware.com' \
--to=roger@nextmovesoftware.com \
--cc=gcc-patches@gcc.gnu.org \
/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).