]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Committed] Bug fix to new wi::bitreverse_large function.
authorRoger Sayle <roger@nextmovesoftware.com>
Wed, 7 Jun 2023 22:40:56 +0000 (23:40 +0100)
committerRoger Sayle <roger@nextmovesoftware.com>
Wed, 7 Jun 2023 22:40:56 +0000 (23:40 +0100)
Richard Sandiford was, of course, right to be warry of new code without
much test coverage.  Converting the nvptx backend to use the BITREVERSE
rtx infrastructure, has resulted in far more exhaustive testing and
revealed a subtle bug in the new wi::bitreverse implementation.  The
code needs to use HOST_WIDE_INT_1U (instead of 1) to avoid unintended
sign extension.

This patch has been tested on nvptx-none hosted on x86_64-pc-linux-gnu
(with a minor tweak to use BITREVERSE), where it fixes regressions of
the 32-bit test vectors in gcc.target/nvptx/brev-2.c and the 64-bit
test vectors in gcc.target/nvptx/brevll-2.c.  Committed as obvious.

2023-06-07  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
* wide-int.cc (wi::bitreverse_large): Use HOST_WIDE_INT_1U to
avoid sign extension/undefined behaviour when setting each bit.

gcc/wide-int.cc

index 24bdce2a656b6aa50dc1466c9c6a7d2366af1058..c6a9e2d49b29bd884366ead5f295bec8d2db6d71 100644 (file)
@@ -786,7 +786,7 @@ wi::bitreverse_large (HOST_WIDE_INT *val, const HOST_WIDE_INT *xval,
          unsigned int d = (precision - 1) - s;
          block = d / HOST_BITS_PER_WIDE_INT;
          offset = d & (HOST_BITS_PER_WIDE_INT - 1);
-          val[block] |= 1 << offset;
+         val[block] |= HOST_WIDE_INT_1U << offset;
        }
     }