public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/110788] New: Spilling to mask register for GPR vec_duplicate
@ 2023-07-24  8:40 rguenth at gcc dot gnu.org
  2023-07-27  7:02 ` [Bug target/110788] " crazylht at gmail dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-24  8:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110788

            Bug ID: 110788
           Summary: Spilling to mask register for GPR vec_duplicate
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rguenth at gcc dot gnu.org
  Target Milestone: ---

double a[1024], b[1024];

void foo (int n)
{
  for (int i = 0; i < n; ++i)
    a[i] = b[i] * 3.;
}

compiled with -O3 -march=cascadelake --param vect-partial-vector-usage=2

produces the inner loop

.L3:
        vmovapd b(%rax), %ymm0{%k1}
        movl    %edx, %ecx
        subl    $4, %edx
        kmovw   %edx, %k0
        vmulpd  %ymm3, %ymm0, %ymm1{%k1}{z}
        vmovapd %ymm1, a(%rax){%k1}
        vpbroadcastmw2d %k0, %xmm1
        addq    $32, %rax
        vpcmpud $6, %xmm2, %xmm1, %k1
        cmpw    $4, %cx
        ja      .L3

where we implement the splat of %edx as

        kmovw   %edx, %k0
        vpbroadcastmw2d %k0, %xmm1

instead of

        vpbroadcastw    %edx, %xmm1

we expand to

(insn 14 13 15 (set (reg:V4SI 96)
        (vec_duplicate:V4SI (reg:SI 93 [ _27 ]))) 8167
{*avx512vl_vec_dup_gprv4si}
     (nil))

but at IRA time we instead match that do

(insn 14 13 15 3 (set (reg:V4SI 96)
        (vec_duplicate:V4SI (zero_extend:SI (subreg:HI (reg/v:SI 95 [ n ])
0)))) 8247 {avx512cd_maskw_vec_dupv4si}
     (expr_list:REG_DEAD (reg/v:SI 95 [ n ]) 
        (nil)))

where combine created this via

Trying 13 -> 14:
   13: r93:SI=zero_extend(r95:SI#0)
      REG_DEAD r95:SI
   14: r96:V4SI=vec_duplicate(r93:SI)
      REG_DEAD r93:SI
Successfully matched this instruction:
(set (reg:V4SI 96)
    (vec_duplicate:V4SI (zero_extend:SI (subreg:HI (reg/v:SI 95 [ n ]) 0))))
allowing combination of insns 13 and 14
original costs 4 + 4 = 8
replacement cost 4

but it didn't anticipate that reg 95 could be allocated to a GPR?  The
vectorizer uses an unsigned short IV for the loop, that's possibly
sub-optimal in this case but important in others.

I suppose it could also be a missed optimization in REE since I think
the HImode regs should already be zero-extended?

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-11-30 10:51 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-24  8:40 [Bug target/110788] New: Spilling to mask register for GPR vec_duplicate rguenth at gcc dot gnu.org
2023-07-27  7:02 ` [Bug target/110788] " crazylht at gmail dot com
2023-07-27  7:09 ` crazylht at gmail dot com
2023-07-27 11:29 ` ubizjak at gmail dot com
2023-07-27 13:55 ` crazylht at gmail dot com
2023-07-28  2:07 ` cvs-commit at gcc dot gnu.org
2023-07-28  2:30 ` crazylht at gmail dot com
2023-11-30 10:51 ` liuhongt at gcc dot gnu.org

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).