public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/113345] New: miss optimization for psign{b,w,d}.
@ 2024-01-12  2:15 liuhongt at gcc dot gnu.org
  2024-01-12  2:30 ` [Bug target/113345] " liuhongt at gcc dot gnu.org
  2024-01-12  3:31 ` liuhongt at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: liuhongt at gcc dot gnu.org @ 2024-01-12  2:15 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113345
           Summary: miss optimization for psign{b,w,d}.
           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: ---

void
foo (short* __restrict a, short* b, short* c)
{
    for (int i = 0; i != 1000; i++)
      {
        a[i] = c[i] < 0 ? -b[i] : b[i];
      }
}

gcc -O2 -mavx2

foo(char*, char*, char*):
  xorl %eax, %eax
  vpxor %xmm2, %xmm2, %xmm2
.L2:
  vmovq (%rsi,%rax), %xmm0
  vmovq (%rdx,%rax), %xmm1
  vpsubb %xmm0, %xmm2, %xmm3
  vpcmpgtb %xmm1, %xmm2, %xmm1
  vpblendvb %xmm1, %xmm3, %xmm0, %xmm0
  vmovq %xmm0, (%rdi,%rax)
  addq $8, %rax
  cmpq $1000, %rax
  jne .L2
  ret

it can be optimized with psignw.


22115(define_insn "<ssse3_avx2>_psign<mode>3"
22116  [(set (match_operand:VI124_AVX2 0 "register_operand" "=x,x")
22117        (unspec:VI124_AVX2
22118          [(match_operand:VI124_AVX2 1 "register_operand" "0,x")
22119           (match_operand:VI124_AVX2 2 "vector_operand" "xja,xjm")]
22120          UNSPEC_PSIGN))]


maybe we can just refactor the pattern as blow, then combine can generate the
pattern for us.

22115(define_insn "<ssse3_avx2>_psign<mode>3"
22116  [(set (match_operand:VI124_AVX2 0 "register_operand" "=x,x")
22117        (unspec:VI124_AVX2
22118          [(match_operand:VI124_AVX2 1 "register_operand" "0,x")
                (neg:VI124:(match_dup 1)
22119           (match_operand:VI124_AVX2 2 "vector_operand" "xja,xjm")]
22120          UNSPEC_PBLENDV))]

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

* [Bug target/113345] miss optimization for psign{b,w,d}.
  2024-01-12  2:15 [Bug target/113345] New: miss optimization for psign{b,w,d} liuhongt at gcc dot gnu.org
@ 2024-01-12  2:30 ` liuhongt at gcc dot gnu.org
  2024-01-12  3:31 ` liuhongt at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: liuhongt at gcc dot gnu.org @ 2024-01-12  2:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Hongtao Liu <liuhongt at gcc dot gnu.org> ---

> 
> maybe we can just refactor the pattern as blow, then combine can generate
> the pattern for us.
> 
> 22115(define_insn "<ssse3_avx2>_psign<mode>3"
> 22116  [(set (match_operand:VI124_AVX2 0 "register_operand" "=x,x")
> 22117        (unspec:VI124_AVX2
> 22118          [(match_operand:VI124_AVX2 1 "register_operand" "0,x")
>                 (neg:VI124:(match_dup 1)
> 22119           (match_operand:VI124_AVX2 2 "vector_operand" "xja,xjm")]
> 22120          UNSPEC_PBLENDV))]

Not for VI2, but ok for VI14.

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

* [Bug target/113345] miss optimization for psign{b,w,d}.
  2024-01-12  2:15 [Bug target/113345] New: miss optimization for psign{b,w,d} liuhongt at gcc dot gnu.org
  2024-01-12  2:30 ` [Bug target/113345] " liuhongt at gcc dot gnu.org
@ 2024-01-12  3:31 ` liuhongt at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: liuhongt at gcc dot gnu.org @ 2024-01-12  3:31 UTC (permalink / raw)
  To: gcc-bugs

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

Hongtao Liu <liuhongt at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #2 from Hongtao Liu <liuhongt at gcc dot gnu.org> ---
I realize it should psignb will select 0 when the second operand is 0.
it's b < 0 ? -a : ((b == 0) ? 0 : a).

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

end of thread, other threads:[~2024-01-12  3:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-12  2:15 [Bug target/113345] New: miss optimization for psign{b,w,d} liuhongt at gcc dot gnu.org
2024-01-12  2:30 ` [Bug target/113345] " liuhongt at gcc dot gnu.org
2024-01-12  3:31 ` 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).