public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "ubizjak at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/109079] Missing optimization for x86 avx intrinsic _mm256_zeroall().
Date: Thu, 09 Mar 2023 22:20:26 +0000	[thread overview]
Message-ID: <bug-109079-4-4Ff5BvyFCj@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-109079-4@http.gcc.gnu.org/bugzilla/>

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

Uroš Bizjak <ubizjak at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|target                      |rtl-optimization

--- Comment #2 from Uroš Bizjak <ubizjak at gmail dot com> ---
(In reply to Richard Biener from comment #1)
> I think it wasn't intended to be used this way, but sure.  Currently it's a
> black-box in the target I think and so nothing sees the redundancy.

_mm256_zeroall is emitted as:

(insn 6 3 7 2 (parallel [
            (unspec_volatile [
                    (const_int 0 [0])
                ] UNSPECV_VZEROALL)
            (set (reg:V8SI 20 xmm0)
                (const_vector:V8SI [
                        (const_int 0 [0]) repeated x8
                    ]))
            (set (reg:V8SI 21 xmm1)
                (const_vector:V8SI [
                        (const_int 0 [0]) repeated x8
                    ]))
...
            (set (reg:V8SI 51 xmm15)
                (const_vector:V8SI [
                        (const_int 0 [0]) repeated x8
                    ]))
        ])

and _mm256_setzero_ps as:

(insn 7 6 8 2 (set (reg:V8SF 83)
        (const_vector:V8SF [
                (const_double:SF 0.0 [0x0.0p+0]) repeated x8
            ]))

There is mode mismatch between (insn 6) and (insn 7) so postreload CSE is not
able to eliminate (insn 7).

Using the following patch^w hack that changes the mode of vzeroall registers:

--cut here--
diff --git a/gcc/config/i386/predicates.md b/gcc/config/i386/predicates.md
index b4d9ab40ab9..cf15ca8f611 100644
--- a/gcc/config/i386/predicates.md
+++ b/gcc/config/i386/predicates.md
@@ -1737,9 +1737,9 @@ (define_predicate "vzeroall_operation"

       if (GET_CODE (elt) != SET
          || GET_CODE (SET_DEST (elt)) != REG
-         || GET_MODE (SET_DEST (elt)) != V8SImode
+         || GET_MODE (SET_DEST (elt)) != V8SFmode
          || REGNO (SET_DEST (elt)) != GET_SSE_REGNO (i)
-         || SET_SRC (elt) != CONST0_RTX (V8SImode))
+         || SET_SRC (elt) != CONST0_RTX (V8SFmode))
        return false;
     }
   return true;
diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index 172ec3bea4f..81e02086606 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -25244,8 +25244,8 @@ (define_expand "avx_vzeroall"

   for (regno = 0; regno < nregs; regno++)
     XVECEXP (operands[0], 0, regno + 1)
-      = gen_rtx_SET (gen_rtx_REG (V8SImode, GET_SSE_REGNO (regno)),
-                    CONST0_RTX (V8SImode));
+      = gen_rtx_SET (gen_rtx_REG (V8SFmode, GET_SSE_REGNO (regno)),
+                    CONST0_RTX (V8SFmode));
 })

 (define_insn "*avx_vzeroall"
--cut here--

the compiler is able to eliminate (insn 7) in postreload pass, producing:

fn:
        vzeroall
        vmovups %ymm0, (%rdi)
        vzeroupper
        ret

It looks to me that postreload CSE should be taught about the equivalence of
vector modes - a V8SFmode zero has the same bit representation as V8SImode zero
(and V4DImode, ...), as long as the mode size is the same.

Recategorizing as rtl-optimization.

      parent reply	other threads:[~2023-03-09 22:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-09 10:26 [Bug target/109079] New: " dorazzsoft at gmail dot com
2023-03-09 12:37 ` [Bug target/109079] " rguenth at gcc dot gnu.org
2023-03-09 17:40 ` pinskia at gcc dot gnu.org
2023-03-09 22:20 ` ubizjak at gmail dot com [this message]

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-109079-4-4Ff5BvyFCj@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).