public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/113622] [11/12/13/14 Regression] ICE with vectors in named registers
Date: Mon, 29 Jan 2024 09:27:35 +0000	[thread overview]
Message-ID: <bug-113622-4-QJI8aXcpJT@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-113622-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #15 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #11)
> I think it is most important we don't ICE and generate correct code.  I
> doubt this is used too much in real-world code, otherwise it would have been
> reported years ago, so how efficient it will be is less important.

We do spill on the read side already.  On the write side the ICE is because
of r0-71337-g1e188d1e130034.  Note we're spilling parts of bitpos to offset:

  /* Otherwise, split it up.  */
  if (offset)
    {
      /* Avoid returning a negative bitpos as this may wreak havoc later.  */
      if (!bit_offset.to_shwi (pbitpos) || maybe_lt (*pbitpos, 0))
        {
          *pbitpos = num_trailing_bits (bit_offset.force_shwi ());
          poly_offset_int bytes = bits_to_bytes_round_down (bit_offset);
          offset = size_binop (PLUS_EXPR, offset,
                               build_int_cst (sizetype, bytes.force_shwi ()));
        }

      *poffset = offset;

but it can also be large positive when the bit amount doesn't fit a HWI.

The flow of 'to' expansion is a bit awkward, but the following properly
spills in case of variable offset and non-MEM_P:

diff --git a/gcc/expr.cc b/gcc/expr.cc
index ee822c11dce..f54d0b1474e 100644
--- a/gcc/expr.cc
+++ b/gcc/expr.cc
@@ -6061,6 +6061,7 @@ expand_assignment (tree to, tree from, bool nontemporal)
            to_rtx = adjust_address (to_rtx, BLKmode, 0);
        }

+      rtx stemp = NULL_RTX, old_to_rtx = NULL_RTX;
       if (offset != 0)
        {
          machine_mode address_mode;
@@ -6070,9 +6071,24 @@ expand_assignment (tree to, tree from, bool nontemporal)
            {
              /* We can get constant negative offsets into arrays with broken
                 user code.  Translate this to a trap instead of ICEing.  */
-             gcc_assert (TREE_CODE (offset) == INTEGER_CST);
-             expand_builtin_trap ();
-             to_rtx = gen_rtx_MEM (BLKmode, const0_rtx);
+             if (TREE_CODE (offset) == INTEGER_CST)
+               {
+                 expand_builtin_trap ();
+                 to_rtx = gen_rtx_MEM (BLKmode, const0_rtx);
+               }
+             /* Else spill for variable offset to the destination.  */
+             else
+               {
+                 gcc_assert (!TREE_CODE (from) == CALL_EXPR
+                             && COMPLETE_TYPE_P (TREE_TYPE (from))
+                             && (TREE_CODE (TYPE_SIZE (TREE_TYPE (from)))
+                                 != INTEGER_CST));
+                 stemp = assign_stack_temp (GET_MODE (to_rtx),
+                                            GET_MODE_SIZE (GET_MODE
(to_rtx)));
+                 emit_move_insn (stemp, to_rtx);
+                 old_to_rtx = to_rtx;
+                 to_rtx = stemp;
+               }
            }

          offset_rtx = expand_expr (offset, NULL_RTX, VOIDmode, EXPAND_SUM);
@@ -6305,6 +6321,9 @@ expand_assignment (tree to, tree from, bool nontemporal)
                                  bitregion_start, bitregion_end,
                                  mode1, from, get_alias_set (to),
                                  nontemporal, reversep);
+         /* Move the temporary storage back to the non-MEM_P.  */
+         if (stemp)
+           emit_move_insn (old_to_rtx, stemp);
        }

       if (result)

  parent reply	other threads:[~2024-01-29  9:27 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-26 20:16 [Bug tree-optimization/113622] New: r14-8450 regression: " xry111 at gcc dot gnu.org
2024-01-26 20:23 ` [Bug tree-optimization/113622] " xry111 at gcc dot gnu.org
2024-01-26 20:31 ` [Bug tree-optimization/113622] " pinskia at gcc dot gnu.org
2024-01-26 20:36 ` xry111 at gcc dot gnu.org
2024-01-26 20:39 ` [Bug tree-optimization/113622] [11/12/13/14 Regression] " jakub at gcc dot gnu.org
2024-01-26 20:43 ` pinskia at gcc dot gnu.org
2024-01-26 20:59 ` pinskia at gcc dot gnu.org
2024-01-27  3:49 ` pinskia at gcc dot gnu.org
2024-01-27 12:11 ` jakub at gcc dot gnu.org
2024-01-29  7:56 ` rguenth at gcc dot gnu.org
2024-01-29  8:45 ` rguenth at gcc dot gnu.org
2024-01-29  8:56 ` jakub at gcc dot gnu.org
2024-01-29  8:58 ` xry111 at gcc dot gnu.org
2024-01-29  9:07 ` jakub at gcc dot gnu.org
2024-01-29  9:09 ` xry111 at gcc dot gnu.org
2024-01-29  9:27 ` rguenth at gcc dot gnu.org [this message]
2024-01-29  9:38 ` rguenth at gcc dot gnu.org
2024-01-29 13:31 ` cvs-commit at gcc dot gnu.org
2024-01-29 13:31 ` cvs-commit at gcc dot gnu.org
2024-01-29 13:32 ` [Bug tree-optimization/113622] [11/12/13 " rguenth at gcc dot gnu.org
2024-01-30  8:34 ` cvs-commit at gcc dot gnu.org
2024-01-30 13:22 ` xry111 at gcc dot gnu.org
2024-01-30 13:27 ` xry111 at gcc dot gnu.org
2024-01-30 14:49 ` rguenther at suse dot de
2024-02-25 13:08 ` xry111 at gcc dot gnu.org
2024-03-21 13:54 ` cvs-commit at gcc dot gnu.org
2024-03-21 13:57 ` rguenth at gcc dot gnu.org
2024-05-06 11:49 ` rguenth 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-113622-4-QJI8aXcpJT@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).