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).

Reply via email to