public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/109778] [13/14 Regression] Wrong code at -O1 and above on x86_64-linux-gnu
Date: Mon, 08 May 2023 22:09:16 +0000	[thread overview]
Message-ID: <bug-109778-4-jwfMQbfvL3@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-109778-4@http.gcc.gnu.org/bugzilla/>

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |aldyh at gcc dot gnu.org,
                   |                            |amacleod at redhat dot com

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Looking at the #c1 -O3 differences, before that the ranger is able to handle
all ranges nicely, as f is being called with [90, 91], which results in [181,
183] before the rotate (which previously wasn't used, but 2 shifts + or), and
because the values in that range are 0xb5, 0xb6 and 0xb7 and that rotated by 4
is 0x5b, 0x6b, 0x7b we made [0x5b, 0x7b] range out of that (i.e. [91, 123]) and
that minus 86 is [5, 37].
Now, with the above mentioned commit, we instead have r>>= 4 in the code,
apparently
that is something range-op.cc doesn't handle (but could, worst case with
pretending it is 2 shifts plus or).  So that is one thing that should be done.

The other is a bug in the wi::[lr]rotate implementation, tree-ssa-ccp.cc is the
only caller of those which passes non-zero width and that is what isn't handled
correctly.

--- gcc/wide-int.h.jj   2023-04-18 11:00:39.926725744 +0200
+++ gcc/wide-int.h      2023-05-08 23:36:41.104412818 +0200
@@ -3187,9 +3187,11 @@ wi::lrotate (const T1 &x, const T2 &y, u
     width = precision;
   WI_UNARY_RESULT (T2) ymod = umod_trunc (y, width);
   WI_UNARY_RESULT (T1) left = wi::lshift (x, ymod);
-  WI_UNARY_RESULT (T1) right = wi::lrshift (x, wi::sub (width, ymod));
+  WI_UNARY_RESULT (T1) right
+    = wi::lrshift (width != precision ? wi::zext (x, width) : x,
+                  wi::sub (width, ymod));
   if (width != precision)
-    return wi::zext (left, width) | wi::zext (right, width);
+    return wi::zext (left, width) | right;
   return left | right;
 }

@@ -3204,10 +3206,11 @@ wi::rrotate (const T1 &x, const T2 &y, u
   if (width == 0)
     width = precision;
   WI_UNARY_RESULT (T2) ymod = umod_trunc (y, width);
-  WI_UNARY_RESULT (T1) right = wi::lrshift (x, ymod);
+  WI_UNARY_RESULT (T1) right
+    = wi::lrshift (width != precision ? wi::zext (x, width) : x, ymod);
   WI_UNARY_RESULT (T1) left = wi::lshift (x, wi::sub (width, ymod));
   if (width != precision)
-    return wi::zext (left, width) | wi::zext (right, width);
+    return wi::zext (left, width) | right;
   return left | right;
 }

fixes it but I wonder if we shouldn't return if (width != precision) wi::sext
(left | right, width); instead or do that depending on is_sign_extended, or do
the extension in the caller (tree-ssa-ccp.cc).

  parent reply	other threads:[~2023-05-08 22:09 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-08 19:18 [Bug c/109778] New: Wrong code at -O3 on x86_64-linux-gnu since GCC-12.2 shaohua.li at inf dot ethz.ch
2023-05-08 19:30 ` [Bug tree-optimization/109778] [12/13/14 Regression] Wrong code at -O1 and above " pinskia at gcc dot gnu.org
2023-05-08 19:31 ` [Bug tree-optimization/109778] [13/14 Regression] Wrong code at -O1 and above on x86_64-linux-gnu pinskia at gcc dot gnu.org
2023-05-08 19:36 ` jakub at gcc dot gnu.org
2023-05-08 22:09 ` jakub at gcc dot gnu.org [this message]
2023-05-09  7:38 ` rguenth at gcc dot gnu.org
2023-05-09 10:11 ` cvs-commit at gcc dot gnu.org
2023-05-09 10:19 ` cvs-commit at gcc dot gnu.org
2023-05-09 10:23 ` [Bug tree-optimization/109778] [10/11/12/13 " jakub at gcc dot gnu.org
2023-05-09 10:49 ` cvs-commit at gcc dot gnu.org
2023-05-09 10:49 ` cvs-commit at gcc dot gnu.org
2023-05-09 10:56 ` cvs-commit at gcc dot gnu.org
2023-05-09 10:56 ` cvs-commit at gcc dot gnu.org
2023-05-09 11:04 ` cvs-commit at gcc dot gnu.org
2023-05-09 11:04 ` cvs-commit at gcc dot gnu.org
2023-05-09 11:10 ` cvs-commit at gcc dot gnu.org
2023-05-09 11:10 ` cvs-commit at gcc dot gnu.org
2023-05-21 16:56 ` jakub 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-109778-4-jwfMQbfvL3@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).