public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "liuhongt at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/114428] New: [x86] psrad xmm, xmm, 16 and pand xmm, const_vector (0xffff x4) can be optimized to psrld
Date: Fri, 22 Mar 2024 05:33:26 +0000	[thread overview]
Message-ID: <bug-114428-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 114428
           Summary: [x86] psrad xmm, xmm, 16 and pand xmm, const_vector
                    (0xffff x4) can be optimized to psrld
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: liuhongt at gcc dot gnu.org
  Target Milestone: ---

typedef unsigned short uint16_t;
typedef short int16_t;

#define QUANT_ONE( coef, mf, f )                \
{ \
    if( (coef) > 0 ) \
        (coef) = (f + (coef)) * (mf) >> 16; \
    else \
        (coef) = - ((f - (coef)) * (mf) >> 16); \
    nz |= (coef); \
}

int quant_4x4( int16_t dct[16], uint16_t mf[16], uint16_t bias[16] )
{
    int nz = 0;
    for( int i = 0; i < 16; i++ )
        QUANT_ONE( dct[i], mf[i], bias[i] );
    return !!nz;
}


gcc -O2 -march=x86-64-v3 -S

        mov     edx, 65535
        vmovd   xmm4, edx
        vpbroadcastd    ymm4, xmm4
        ...
        vpsrad  ymm2, ymm2, 16
        vpsrad  ymm6, ymm6, 16
        vpsrad  ymm0, ymm0, 16
        vpand   ymm2, ymm4, ymm2
        vpsrad  ymm1, ymm1, 16
        vpand   ymm6, ymm4, ymm6
        vpand   ymm0, ymm4, ymm0
        vpand   ymm4, ymm4, ymm1
        vpackusdw       ymm2, ymm2, ymm6
        vpackusdw       ymm0, ymm0, ymm4
        vpermq  ymm2, ymm2, 216
        vpermq  ymm0, ymm0, 216
        ...

it can be optimized to below.

        vpsrld  ymm2, ymm2, 16
        vpsrld  ymm6, ymm6, 16
        vpsrld  ymm0, ymm0, 16
        vpsrld  ymm1, ymm1, 16
        vpackusdw       ymm2, ymm2, ymm6
        vpackusdw       ymm0, ymm0, ymm4
        vpermq  ymm2, ymm2, 216
        vpermq  ymm0, ymm0, 216

The optimization opportunity is exposed after vec_pack_trunk_expr is expanded
to vpand + vpackusdw.

             reply	other threads:[~2024-03-22  5:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-22  5:33 liuhongt at gcc dot gnu.org [this message]
2024-06-06  0:36 ` [Bug target/114428] " cvs-commit at gcc dot gnu.org
2024-06-06  0:36 ` cvs-commit at gcc dot gnu.org
2024-06-06  0:49 ` liuhongt at gcc dot gnu.org

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=bug-114428-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).