From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by sourceware.org (Postfix) with ESMTPS id 3B35D382D824 for ; Tue, 5 Jan 2021 07:05:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3B35D382D824 Received: by mail-qk1-x72e.google.com with SMTP id 186so25743429qkj.3 for ; Mon, 04 Jan 2021 23:05:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=xJwZnl8NigUy7z7MNeXIQ9/24LeP1/paYaPWzYkCGMU=; b=jRI1Ok/JVWlm1Y1/nTVaAGxMnryQFGgB4/8l8PodTS3k+ynMqeHj1UxLvTc3q9c4WV x5uwh3ggPtbIDTI45H3c+dq01vgPlpJb2xawOMfAtQh4+9eJn7y+dMbHwRniggmqq5uh Xor6WZmKYTYga16QlI5/sfttwIjHC8ldcbnHcfvye9PZZELGep+b0w7B1QS2g7nvGuzN x+b/RwXPoj4s2TEmGhU2/u6Jrfe8EEn99kS/6yTxe06DmpVgN9+MdXHlcTHyLSVJzgN7 FkcmyOsvd1l+ddqn2ISMuIv3ixN3USBCKWiUdbc4ztblYhNmogC5zSn41206sc0QEj41 TDTw== X-Gm-Message-State: AOAM530zMuzHWZGRL4Za8cjvEerYQKIPd+7AkJZpe+4Fzw0ZplYvC/0E 5FJqMmbtCgdw+KJzKi/9+L7lO9GhVMsaOLijQbs= X-Google-Smtp-Source: ABdhPJw0wG5/YPWrgGxocnKZvjxeyB/lWV1C3bSJC9VeX3uQ3FdZING7nzv21Kg00+AJcOSVPJJL8MdIN41/pf+G0ak= X-Received: by 2002:a37:458:: with SMTP id 85mr72456951qke.61.1609830308770; Mon, 04 Jan 2021 23:05:08 -0800 (PST) MIME-Version: 1.0 References: <20210104084920.GK3788@tucnak> In-Reply-To: From: Uros Bizjak Date: Tue, 5 Jan 2021 08:04:57 +0100 Message-ID: Subject: Re: [PATCH]i386: Optimize pmovskb on zero_extend of subreg HI of the result [PR98461] To: Hongtao Liu Cc: Jakub Jelinek , GCC Patches , Kirill Yukhin Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Jan 2021 07:05:10 -0000 On Tue, Jan 5, 2021 at 7:30 AM Hongtao Liu wrote: > > On Mon, Jan 4, 2021 at 4:59 PM Hongtao Liu wrote: > > > > On Mon, Jan 4, 2021 at 4:49 PM Jakub Jelinek wrote: > > > > > > On Mon, Jan 04, 2021 at 01:56:44PM +0800, Hongtao Liu via Gcc-patches wrote: > > > > +(define_insn_and_split "*sse2_pmovskb_zexthisi" > > > > + [(set (match_operand:SI 0 "register_operand") > > > > + (zero_extend:SI (subreg:HI (unspec:SI > > > > + [(match_operand:V16QI 1 "register_operand")] > > > > + UNSPEC_MOVMSK) 0)))] > > > > > > Also, please fix up formatting. Should be: > > > (zero_extend:SI > > > (subreg:HI > > > (unspec:SI > > > [(match_operand:V16QI 1 "register_operand")] > > > UNSPEC_MOVMSK) 0)))] > > > I think. > > > > > > Jakub > > > > > > > Yes, thanks for the review both, and happy new year! > > > > -- > > BR, > > Hongtao > > Sorry for the bother, this is an incremental patch to split > (zero_extend:SI (not:HI (subreg:HI (pmovmskb result:SI)))) to > > pmovmskb %xmm0, %eax > - notl %eax > - movzwl %ax, %eax > + xorl $65535, %eax > > > The patch is below, regtestes and bootstrapped on x86_64-linux-gnu{-m32,}. > Ok for trunk? > > The following patch adds define_insn_and_split to optimize > > vpmovmskb %xmm0, %eax > - movzwl %ax, %eax > notl %eax > > and combine splitter to optimize > > pmovmskb %xmm0, %eax > - notl %eax > - movzwl %ax, %eax > + xorl $65535, %eax > > gcc/ChangeLog > PR target/98461 > * config/i386/sse.md (*sse2_pmovskb_zexthisi): New > define_insn_and_split for zero_extend of subreg HI of pmovskb > result. > (*sse2_pmovskb_zexthisi): Add new combine splitters for > zero_extend of not of subreg HI of pmovskb result. > > gcc/testsuite/ChangeLog > * gcc.target/i386/sse-pr98461-2.c: New test. > --- > gcc/config/i386/sse.md | 32 +++++++++++++++++++ > .../gcc.target/i386/sse2-pr98461-2.c | 25 +++++++++++++++ > 2 files changed, 57 insertions(+) > create mode 100644 gcc/testsuite/gcc.target/i386/sse2-pr98461-2.c > > diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md > index d84103807ff..4fcff0800c0 100644 > --- a/gcc/config/i386/sse.md > +++ b/gcc/config/i386/sse.md > @@ -16099,6 +16099,38 @@ (define_insn "*sse2_pmovmskb_ext" > (set_attr "prefix" "maybe_vex") > (set_attr "mode" "SI")]) > > +(define_insn_and_split "*sse2_pmovskb_zexthisi" > + [(set (match_operand:SI 0 "register_operand") > + (zero_extend:SI > + (subreg:HI > + (unspec:SI > + [(match_operand:V16QI 1 "register_operand")] > + UNSPEC_MOVMSK) 0)))] > + "TARGET_SSE2 && ix86_pre_reload_split ()" > + "#" > + "&& 1" > + [(set (match_dup 0) > + (unspec:SI [(match_dup 1)] UNSPEC_MOVMSK))]) > + > +(define_split > + [(set (match_operand:SI 0 "register_operand") > + (zero_extend:SI > + (not:HI > + (subreg:HI > + (unspec:SI > + [(match_operand:V16QI 1 "register_operand")] > + UNSPEC_MOVMSK) 0))))] > + "TARGET_SSE2" > + [(set (match_dup 2) > + (unspec:SI [(match_dup 1)] UNSPEC_MOVMSK)) > + (set (match_dup 0) > + (match_dup 3))] Just write: (set (match_dup 0) (xor:SI (match_dup 2)(const_int 65535)) Uros. > > +{ > + operands[2] = gen_reg_rtx (SImode); > + operands[3] = gen_int_mode ((HOST_WIDE_INT_1 << 16) - 1, SImode); > + operands[3] = gen_rtx_XOR (SImode, operands[2], operands[3]); > +}) > + > (define_split > [(set (match_operand:SI 0 "register_operand") > (unspec:SI > diff --git a/gcc/testsuite/gcc.target/i386/sse2-pr98461-2.c > b/gcc/testsuite/gcc.target/i386/sse2-pr98461-2.c > new file mode 100644 > index 00000000000..330272c69bc > --- /dev/null > +++ b/gcc/testsuite/gcc.target/i386/sse2-pr98461-2.c > @@ -0,0 +1,25 @@ > +/* PR target/98461 */ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -msse2 -mno-sse3 -masm=att" } */ > +/* { dg-final { scan-assembler-times "\tpmovmskb\t" 3 } } */ > +/* { dg-final { scan-assembler-not "\tmovzwl" } } */ > +/* { dg-final { scan-assembler-times "\tnotl" 1 } } * > +/* { dg-final { scan-assembler-times "\txorl" 1 } } */ > + > +#include > + > +unsigned int movemask_not1(__m128i logical) { > + unsigned short res = (unsigned short)(_mm_movemask_epi8(logical)); > + return ~res; > +} > + > +unsigned int movemask_not2(__m128i logical) { > + unsigned short res = (unsigned short)(_mm_movemask_epi8(logical)); > + res = ~res; > + return res; > +} > + > +unsigned int movemask_zero_extend(__m128i logical) { > + unsigned int res = _mm_movemask_epi8(logical); > + return res & 0xffff; > +} > -- > 2.18.1 > > > -- > BR, > Hongtao