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 middle-end/110495] fre introduces signed wrap for vector
Date: Fri, 30 Jun 2023 09:33:09 +0000	[thread overview]
Message-ID: <bug-110495-4-Gqm3uDzO51@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-110495-4@http.gcc.gnu.org/bugzilla/>

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu.org,
                   |                            |rsandifo at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |wrong-code
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-06-30
          Component|tree-optimization           |middle-end

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Applying pattern match.pd:3029, gimple-match-2.cc:1090
Applying pattern match.pd:3029, gimple-match-2.cc:1090

but that specifically checks for

         (if (cst && !TREE_OVERFLOW (cst))
          (inner_op @0 { cst; } )

ah, but we are dealing with vectors here and the VECTOR_CST doesn't
inherit TREE_OVERFLOW here.  I don't think we ever actually set
TREE_OVERFLOW on VECTOR_CSTs even though that's documented to be a thing.

We are relying on TREE_OVERFLOW in some more patterns that are also
applying to VECTOR_CST.  _Complex int is probably similarly affected.

diff --git a/gcc/tree-vector-builder.cc b/gcc/tree-vector-builder.cc
index 0e51bcefa4f..78688ef4331 100644
--- a/gcc/tree-vector-builder.cc
+++ b/gcc/tree-vector-builder.cc
@@ -43,6 +43,12 @@ tree_vector_builder::build ()
   gcc_assert (pow2p_hwi (npatterns ()));
   tree v = make_vector (exact_log2 (npatterns ()), nelts_per_pattern ());
   TREE_TYPE (v) = m_type;
+  bool ovf = false;
+  for (tree elt : *this)
+    if (TREE_OVERFLOW (elt))
+      ovf = true;
+  if (ovf)
+    TREE_OVERFLOW (v) = true;
   memcpy (VECTOR_CST_ENCODED_ELTS (v), address (),
          encoded_nelts () * sizeof (tree));
   return v;

fixes this and results in

  <bb 2> :
  _1 = *x_6(D);
  _2 = _1 + { 2147483647, 2147483647, 2147483647, 2147483647, 2147483647,
2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2147483647,
2147483647, 2147483647, 2147483647, 2147483647, 2147483647 };
  *x_6(D) = _2;
  _9 = VIEW_CONVERT_EXPR<vector(16) unsigned int>(_1);
  _10 = _9 + { 4294967294, 4294967294, 4294967294, 4294967294, 4294967294,
4294967294, 4294967294, 4294967294, 4294967294, 4294967294, 4294967294,
4294967294, 4294967294, 4294967294, 4294967294, 4294967294 };
  _4 = VIEW_CONVERT_EXPR<vector(16) int>(_10);
  *x_6(D) = _4;
  return;

there are some more VECTOR_CST builders that would need adjustment for
consistency.  Maybe not relying on TREE_OVERFLOW would be a better idea
here, but while for plain integers we have wide_int for vectors or
complex there's no such thing ...

  reply	other threads:[~2023-06-30  9:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-30  9:06 [Bug tree-optimization/110495] New: " kristerw at gcc dot gnu.org
2023-06-30  9:33 ` rguenth at gcc dot gnu.org [this message]
2023-07-03  8:09 ` [Bug middle-end/110495] " rsandifo at gcc dot gnu.org
2023-07-03  8:40 ` rguenth at gcc dot gnu.org
2023-07-03  8:43 ` rguenth at gcc dot gnu.org
2023-07-04  7:08 ` cvs-commit at gcc dot gnu.org
2023-07-04  7:09 ` 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-110495-4-Gqm3uDzO51@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).