public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "crazylht at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/104610] memcmp () == 0 can be optimized better for avx512f
Date: Wed, 23 Feb 2022 02:15:49 +0000	[thread overview]
Message-ID: <bug-104610-4-HNo1GEvd84@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-104610-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #7 from Hongtao.liu <crazylht at gmail dot com> ---
(In reply to Hongtao.liu from comment #6)
> (In reply to Hongtao.liu from comment #5)
> > (In reply to Hongtao.liu from comment #4)
> > > (In reply to Hongtao.liu from comment #3)
> > > > (In reply to Hongtao.liu from comment #2)
> > > > > in Gimple, there're
> > > > > 
> > > > >   _1 = __builtin_memcmp_eq (a_5(D), &t[0], 32);
> > > > >   _2 = _1 == 0;
> > > > >   _6 = (int) _2;
> > > > > 
> > > > > 
> > > > > So it's related to codegen optimization with vectorized codes for
> > > > > __builtin_memcmp_eq, guess we can start with size multiple of 16 bytes?
> > > > > 
> > > > There's no optab or target_hook for backend to participate in optimization
> > But there's cbranch_optab check in can_compare_p, and i386 supports
> > V8SI/V4DI/V4SI/V2DI, but not for OI/TI, adding support for them?
> > 
> > 25899(define_expand "cbranch<mode>4"
> > 25900  [(set (reg:CC FLAGS_REG)
> > 25901        (compare:CC (match_operand:VI48_AVX 1 "register_operand")
> > 25902                    (match_operand:VI48_AVX 2 "nonimmediate_operand")))
> > 25903   (set (pc) (if_then_else
> > 25904               (match_operator 0 "bt_comparison_operator"
> > 25905                [(reg:CC FLAGS_REG) (const_int 0)])
> > 25906               (label_ref (match_operand 3))
> 
> After supporting cbranchoi4, gcc generates
> 
> _Z1fPc:
> .LFB0:
>         .cfi_startproc
>         vmovdqa .LC1(%rip), %ymm0
>         vpxor   (%rdi), %ymm0, %ymm0
>         vptest  %ymm0, %ymm0
>         sete    %al
>         vzeroupper
> 
> which is optimal as clang/llvm does.

Also extend cbranchti to ptest when target_sse4_1 and CODE == NE || CODE == EQ
so gcc generates 

        movdqu  (%rdi), %xmm0
        movdqa  .LC1(%rip), %xmm1
        pxor    %xmm1, %xmm0
        ptest   %xmm0, %xmm0
        sete    %al

for 

bool f128(char *a)
{
  char t[] = "012345678901234";
  return __builtin_memcmp(a, &t[0], sizeof(t)) == 0;
}

the original codegen is

        movabsq $14692989455579448, %rax
        xorq    8(%rdi), %rax
        movabsq $3978425819141910832, %rdx
        xorq    (%rdi), %rdx
        orq     %rdx, %rax
        sete    %al
        ret

  parent reply	other threads:[~2022-02-23  2:15 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-21 11:00 [Bug target/104610] New: " pinskia at gcc dot gnu.org
2022-02-21 11:01 ` [Bug target/104610] " pinskia at gcc dot gnu.org
2022-02-22  4:03 ` crazylht at gmail dot com
2022-02-22  5:54 ` crazylht at gmail dot com
2022-02-22  5:55 ` crazylht at gmail dot com
2022-02-22  6:18 ` crazylht at gmail dot com
2022-02-22  6:32 ` crazylht at gmail dot com
2022-02-23  2:15 ` crazylht at gmail dot com [this message]
2022-02-23  6:18 ` crazylht at gmail dot com
2022-02-23 21:04 ` hjl.tools at gmail dot com
2022-02-24  5:33 ` crazylht at gmail dot com
2022-02-24  6:00 ` hjl.tools at gmail dot com
2022-02-26 20:26 ` hjl.tools at gmail dot com
2022-02-27 19:02 ` hjl.tools at gmail dot com
2022-02-27 19:29 ` hjl.tools at gmail dot com
2022-03-04  3:03 ` hjl.tools at gmail dot com
2022-03-28  5:05 ` crazylht at gmail dot com
2022-03-28  5:27 ` crazylht at gmail dot com
2022-05-18  2:47 ` cvs-commit at gcc dot gnu.org
2022-05-18  2:49 ` crazylht at gmail dot com
2022-06-16  7:41 ` crazylht at gmail dot com
2023-06-28 10:12 ` cvs-commit at gcc dot gnu.org
2023-06-28 11:05 ` ubizjak at gmail dot com
2023-10-10  7:37 ` crazylht at gmail dot com
2023-10-30  3:10 ` cvs-commit 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-104610-4-HNo1GEvd84@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).