public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/101989] New: Fail to optimize (a & b) | (c & ~b) to vpternlog instruction.
@ 2021-08-20  1:46 crazylht at gmail dot com
  2021-08-20  1:50 ` [Bug target/101989] " crazylht at gmail dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: crazylht at gmail dot com @ 2021-08-20  1:46 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101989
           Summary: Fail to optimize (a & b) | (c & ~b) to vpternlog
                    instruction.
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: crazylht at gmail dot com
  Target Milestone: ---
              Host: x86_64-pc-linux-gnu
            Target: x86_64-*-* i?86-*-*

cat test.c

__m128i foo (__m128i src1, __m128i src2, __m128i src3)
{
  return (src2 & ~src1) | (src3 & src1);
}

__m128i foo1 (__m128i src1, __m128i src2, __m128i src3)
{
  return (src2 & src1) | (src3 & ~src1);
}

gcc -O2 -march=cascadelake  generates

foo(long long __vector(2), long long __vector(2), long long __vector(2)):
        vpxor   %xmm2, %xmm1, %xmm2
        vpand   %xmm0, %xmm2, %xmm2
        vpxor   %xmm1, %xmm2, %xmm0
        ret
foo1(long long __vector(2), long long __vector(2), long long __vector(2)):
        vpxor   %xmm2, %xmm1, %xmm1
        vpand   %xmm0, %xmm1, %xmm1
        vpxor   %xmm2, %xmm1, %xmm0
        ret


icx generates

foo(long long __vector(2), long long __vector(2), long long __vector(2)):      
                 # 
        vpternlogq      xmm0, xmm2, xmm1, 202
        ret
foo1(long long __vector(2), long long __vector(2), long long __vector(2)):     
                 # 
        vpternlogq      xmm0, xmm1, xmm2, 202
        ret

Guess we need a post_reload splitter to match

Failed to match this instruction:
(set (reg:V2DI 88)
    (xor:V2DI (and:V2DI (xor:V2DI (reg:V2DI 92)
                (reg/v:V2DI 87 [ src3 ]))
            (reg:V2DI 91))
        (reg/v:V2DI 87 [ src3 ])))
Failed to match this instruction:

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

* [Bug target/101989] Fail to optimize (a & b) | (c & ~b) to vpternlog instruction.
  2021-08-20  1:46 [Bug target/101989] New: Fail to optimize (a & b) | (c & ~b) to vpternlog instruction crazylht at gmail dot com
@ 2021-08-20  1:50 ` crazylht at gmail dot com
  2021-08-20  2:00 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: crazylht at gmail dot com @ 2021-08-20  1:50 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Hongtao.liu <crazylht at gmail dot com> ---
Another testcase is from pr91796

    __m256d copysign2_pd(__m256d from, __m256d to) {
        auto a = _mm256_castpd_si256(from);
        auto avx_signbit =
_mm256_castsi256_pd(_mm256_slli_epi64(_mm256_cmpeq_epi64(a, a), 63));
        return _mm256_or_pd(_mm256_and_pd(avx_signbit, from),
_mm256_andnot_pd(avx_signbit, to)); // (avx_signbit & from) | (~avx_signbit &
to)
    }


Failed to match this instruction:
(set (reg:V4DF 93)
    (ior:V4DF (and:V4DF (reg:V4DF 89)
            (reg:V4DF 95))
        (and:V4DF (not:V4DF (reg:V4DF 89))
            (reg:V4DF 96))))
Failed to match this instruction:

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

* [Bug target/101989] Fail to optimize (a & b) | (c & ~b) to vpternlog instruction.
  2021-08-20  1:46 [Bug target/101989] New: Fail to optimize (a & b) | (c & ~b) to vpternlog instruction crazylht at gmail dot com
  2021-08-20  1:50 ` [Bug target/101989] " crazylht at gmail dot com
@ 2021-08-20  2:00 ` pinskia at gcc dot gnu.org
  2021-08-24  9:45 ` cvs-commit at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-20  2:00 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-08-20
             Status|UNCONFIRMED                 |NEW
           Severity|normal                      |enhancement
     Ever confirmed|0                           |1
               Host|x86_64-pc-linux-gnu         |

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.  You might be able to handle it with a match_dup instead of needing
a post_reload splitter to match the the one reg that needs to be the same.

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

* [Bug target/101989] Fail to optimize (a & b) | (c & ~b) to vpternlog instruction.
  2021-08-20  1:46 [Bug target/101989] New: Fail to optimize (a & b) | (c & ~b) to vpternlog instruction crazylht at gmail dot com
  2021-08-20  1:50 ` [Bug target/101989] " crazylht at gmail dot com
  2021-08-20  2:00 ` pinskia at gcc dot gnu.org
@ 2021-08-24  9:45 ` cvs-commit at gcc dot gnu.org
  2021-08-24 10:34 ` cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-08-24  9:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by hongtao Liu <liuhongt@gcc.gnu.org>:

https://gcc.gnu.org/g:6ddb30f941a44bd528904558673ab35394565f08

commit r12-3108-g6ddb30f941a44bd528904558673ab35394565f08
Author: liuhongt <hongtao.liu@intel.com>
Date:   Fri Aug 20 15:30:40 2021 +0800

    Optimize (a & b) | (c & ~b) to vpternlog instruction.

    Also optimize below 3 forms to vpternlog, op1, op2, op3 are
    register_operand or unary_p as (not reg)

    A: (any_logic (any_logic op1 op2) op3)
    B: (any_logic (any_logic op1 op2) (any_logic op3 op4)) op3/op4 should
    be equal to op1/op2
    C: (any_logic (any_logic (any_logic:op1 op2) op3) op4) op3/op4 should
    be equal to op1/op2

    gcc/ChangeLog:

            PR target/101989
            * config/i386/i386.c (ix86_rtx_costs): Define cost for
            UNSPEC_VTERNLOG.
            * config/i386/i386.h (STRIP_UNARY): New macro.
            * config/i386/predicates.md (reg_or_notreg_operand): New
            predicate.
            * config/i386/sse.md (*<avx512>_vternlog<mode>_all): New
define_insn.
            (*<avx512>_vternlog<mode>_1): New pre_reload
            define_insn_and_split.
            (*<avx512>_vternlog<mode>_2): Ditto.
            (*<avx512>_vternlog<mode>_3): Ditto.
            (any_logic1,any_logic2): New code iterator.
            (logic_op): New code attribute.
            (ternlogsuffix): Extend to VNxDF and VNxSF.

    gcc/testsuite/ChangeLog:

            PR target/101989
            * gcc.target/i386/pr101989-1.c: New test.
            * gcc.target/i386/pr101989-2.c: New test.
            * gcc.target/i386/avx512bw-shiftqihi-constant-1.c: Adjust testcase.

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

* [Bug target/101989] Fail to optimize (a & b) | (c & ~b) to vpternlog instruction.
  2021-08-20  1:46 [Bug target/101989] New: Fail to optimize (a & b) | (c & ~b) to vpternlog instruction crazylht at gmail dot com
                   ` (2 preceding siblings ...)
  2021-08-24  9:45 ` cvs-commit at gcc dot gnu.org
@ 2021-08-24 10:34 ` cvs-commit at gcc dot gnu.org
  2021-08-24 10:35 ` crazylht at gmail dot com
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-08-24 10:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by hongtao Liu <liuhongt@gcc.gnu.org>:

https://gcc.gnu.org/g:8da9b4f73c2c878b48f45fa2ed47d8a9edd31262

commit r12-3109-g8da9b4f73c2c878b48f45fa2ed47d8a9edd31262
Author: liuhongt <hongtao.liu@intel.com>
Date:   Tue Aug 24 18:09:33 2021 +0800

    Enable avx512 embedde broadcast for vpternlog.

    gcc/ChangeLog:

            PR target/101989
            * config/i386/sse.md (<avx512>_vternlog<mode><sd_maskz_name>):
            Enable avx512 embedded broadcast.
            (*<avx512>_vternlog<mode>_all): Ditto.
            (<avx512>_vternlog<mode>_mask): Ditto.

    gcc/testsuite/ChangeLog:

            PR target/101989
            * gcc.target/i386/pr101989-broadcast-1.c: New test.

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

* [Bug target/101989] Fail to optimize (a & b) | (c & ~b) to vpternlog instruction.
  2021-08-20  1:46 [Bug target/101989] New: Fail to optimize (a & b) | (c & ~b) to vpternlog instruction crazylht at gmail dot com
                   ` (3 preceding siblings ...)
  2021-08-24 10:34 ` cvs-commit at gcc dot gnu.org
@ 2021-08-24 10:35 ` crazylht at gmail dot com
  2021-08-25  1:57 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: crazylht at gmail dot com @ 2021-08-24 10:35 UTC (permalink / raw)
  To: gcc-bugs

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

Hongtao.liu <crazylht at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Hongtao.liu <crazylht at gmail dot com> ---
Fixed in GCC12.

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

* [Bug target/101989] Fail to optimize (a & b) | (c & ~b) to vpternlog instruction.
  2021-08-20  1:46 [Bug target/101989] New: Fail to optimize (a & b) | (c & ~b) to vpternlog instruction crazylht at gmail dot com
                   ` (4 preceding siblings ...)
  2021-08-24 10:35 ` crazylht at gmail dot com
@ 2021-08-25  1:57 ` cvs-commit at gcc dot gnu.org
  2021-08-25  2:32 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-08-25  1:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by hongtao Liu <liuhongt@gcc.gnu.org>:

https://gcc.gnu.org/g:4f5391dde1a83086b451f7534c815ab1267bb6bc

commit r12-3133-g4f5391dde1a83086b451f7534c815ab1267bb6bc
Author: liuhongt <hongtao.liu@intel.com>
Date:   Wed Aug 25 09:45:25 2021 +0800

    Adjust testcases to avoid new failures brought by r12-3108 when compiled w
-march=cascadelake.

    gcc/testsuite/ChangeLog:

            PR target/101989
            * gcc.target/i386/avx2-shiftqihi-constant-1.c: Add -mno-avx512f.
            * gcc.target/i386/sse2-shiftqihi-constant-1.c: Add -mno-avx

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

* [Bug target/101989] Fail to optimize (a & b) | (c & ~b) to vpternlog instruction.
  2021-08-20  1:46 [Bug target/101989] New: Fail to optimize (a & b) | (c & ~b) to vpternlog instruction crazylht at gmail dot com
                   ` (5 preceding siblings ...)
  2021-08-25  1:57 ` cvs-commit at gcc dot gnu.org
@ 2021-08-25  2:32 ` pinskia at gcc dot gnu.org
  2021-11-04  8:10 ` cvs-commit at gcc dot gnu.org
  2022-09-25 19:35 ` ak at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-25  2:32 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.0

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

* [Bug target/101989] Fail to optimize (a & b) | (c & ~b) to vpternlog instruction.
  2021-08-20  1:46 [Bug target/101989] New: Fail to optimize (a & b) | (c & ~b) to vpternlog instruction crazylht at gmail dot com
                   ` (6 preceding siblings ...)
  2021-08-25  2:32 ` pinskia at gcc dot gnu.org
@ 2021-11-04  8:10 ` cvs-commit at gcc dot gnu.org
  2022-09-25 19:35 ` ak at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-11-04  8:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by hongtao Liu <liuhongt@gcc.gnu.org>:

https://gcc.gnu.org/g:bc9c8e5f8af08c513a4a4c329c50ba6559ff6d5c

commit r12-4882-gbc9c8e5f8af08c513a4a4c329c50ba6559ff6d5c
Author: liuhongt <hongtao.liu@intel.com>
Date:   Wed Nov 3 16:32:22 2021 +0800

    Extend vternlog define_insn_and_split to memory_operand to enable more
optimziation.

    gcc/ChangeLog:

            PR target/101989
            * config/i386/predicates.md (reg_or_notreg_operand): Rename to ..
            (regmem_or_bitnot_regmem_operand): .. and extend to handle
            memory_operand.
            * config/i386/sse.md (*<avx512>_vpternlog<mode>_1): Force_reg
            the operands which are required to be register_operand.
            (*<avx512>_vpternlog<mode>_2): Ditto.
            (*<avx512>_vpternlog<mode>_3): Ditto.
            (*<avx512>_vternlog<mode>_all): Disallow embeded broadcast for
            vector HFmodes since it's not a real AVX512FP16 instruction.

    gcc/testsuite/ChangeLog:

            * gcc.target/i386/pr101989-3.c: New test.

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

* [Bug target/101989] Fail to optimize (a & b) | (c & ~b) to vpternlog instruction.
  2021-08-20  1:46 [Bug target/101989] New: Fail to optimize (a & b) | (c & ~b) to vpternlog instruction crazylht at gmail dot com
                   ` (7 preceding siblings ...)
  2021-11-04  8:10 ` cvs-commit at gcc dot gnu.org
@ 2022-09-25 19:35 ` ak at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: ak at gcc dot gnu.org @ 2022-09-25 19:35 UTC (permalink / raw)
  To: gcc-bugs

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

ak at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rth at gcc dot gnu.org

--- Comment #8 from ak at gcc dot gnu.org ---
*** Bug 93768 has been marked as a duplicate of this bug. ***

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

end of thread, other threads:[~2022-09-25 19:35 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-20  1:46 [Bug target/101989] New: Fail to optimize (a & b) | (c & ~b) to vpternlog instruction crazylht at gmail dot com
2021-08-20  1:50 ` [Bug target/101989] " crazylht at gmail dot com
2021-08-20  2:00 ` pinskia at gcc dot gnu.org
2021-08-24  9:45 ` cvs-commit at gcc dot gnu.org
2021-08-24 10:34 ` cvs-commit at gcc dot gnu.org
2021-08-24 10:35 ` crazylht at gmail dot com
2021-08-25  1:57 ` cvs-commit at gcc dot gnu.org
2021-08-25  2:32 ` pinskia at gcc dot gnu.org
2021-11-04  8:10 ` cvs-commit at gcc dot gnu.org
2022-09-25 19:35 ` ak 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).