From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1251) id 3B0F138582BD; Wed, 7 Jun 2023 22:42:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3B0F138582BD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686177737; bh=AFfnNHDztA0cbqtxrdWpNrB90Cif94lK7G7xbkxH9IU=; h=From:To:Subject:Date:From; b=xzQoJSH4xoR8nJCG4bQ0Y3J6YXDdh8iU8rrsfPGWzimWnS13rZ9XxMZ5QkcIhLklJ b1Ct8KnSXI7M9OeDbKVy+0EU0ubdp+GzddpPY+BkLMfYX/PQsGvDoXOoJqMnAmg4bJ zF3onc4AX6HpMC9zyNLJZ8vIKnOhgviqKyK/wqD0= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Roger Sayle To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-1626] [Committed] Bug fix to new wi::bitreverse_large function. X-Act-Checkin: gcc X-Git-Author: Roger Sayle X-Git-Refname: refs/heads/master X-Git-Oldrev: eba3565ce6d766c006cbf1f7f293bbd1226a682d X-Git-Newrev: e73a307f5027aeb124fa824621ad980aa983931b Message-Id: <20230607224217.3B0F138582BD@sourceware.org> Date: Wed, 7 Jun 2023 22:42:17 +0000 (GMT) List-Id: https://gcc.gnu.org/g:e73a307f5027aeb124fa824621ad980aa983931b commit r14-1626-ge73a307f5027aeb124fa824621ad980aa983931b Author: Roger Sayle Date: Wed Jun 7 23:40:56 2023 +0100 [Committed] Bug fix to new wi::bitreverse_large function. 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 gcc/ChangeLog * wide-int.cc (wi::bitreverse_large): Use HOST_WIDE_INT_1U to avoid sign extension/undefined behaviour when setting each bit. Diff: --- gcc/wide-int.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/wide-int.cc b/gcc/wide-int.cc index 24bdce2a656..c6a9e2d49b2 100644 --- a/gcc/wide-int.cc +++ b/gcc/wide-int.cc @@ -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; } }