From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0AB133857C61; Sat, 3 Feb 2024 13:39:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0AB133857C61 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1706967552; bh=ksTGDzyIrNcQG7Uy78u8lIDjpvxL3XQhzteU9wqQh9g=; h=From:To:Subject:Date:In-Reply-To:References:From; b=U6NCOda/8ODztj9wlRA2Bc8AkoCpBVqRB63PheBuibdrJpZkXtASwBEoWEqFEYT+R UeL3cJpoWg1XIzjA2BbFtKmY6P83R89exb64kf5gMBBmtmgI5h2mL8FbtYfld6hof/ km9AwMhO3uuust2HwmQ9yb8u6VaQ1ThV6o0qi1yM= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/113722] [14 Regression] Constant folding of __builtin_bswap128 is broken since r14-1455 Date: Sat, 03 Feb 2024 13:39:10 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: jakub at gcc dot gnu.org X-Bugzilla-Target-Milestone: 14.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D113722 --- Comment #5 from GCC Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:09df058a09f888daad26fa80634068b38b4ad04d commit r14-8776-g09df058a09f888daad26fa80634068b38b4ad04d Author: Jakub Jelinek Date: Sat Feb 3 14:38:27 2024 +0100 wide-int: Fix up wi::bswap_large [PR113722] Since bswap has been converted from a method to a function we miscompile the following testcase. The problem is the assumption that the passed = in len argument (number of limbs in the xval array) is the upper bound for= the bswap result, which is true only if precision is <=3D 64. If precision= is larger than that, e.g. 128 as in the testcase, if the argument has only one limb (i.e. 0 to ~(unsigned HOST_WIDE_INT) 0), the result can still need 2 limbs for that precision, or generally BLOCKS_NEEDED (precision) limbs, it all depends on how many least significant limbs of the operand are zero. bswap_large as implemented only cleared len limbs of result, then swapped the bytes (invoking UB when oring something in all the lim= bs above it) and finally passed len to canonize, saying that more limbs aren't needed. The following patch fixes it by renaming len to xlen (so that it is cle= ar it is X's length), using it solely for safe_uhwi argument when we attem= pt to read from X, and using new len =3D BLOCKS_NEEDED (precision) instead= in the other two spots (i.e. when clearing the val array, turned it also into memset, and in canonize argument). wi::bswap asserts it isn't inv= oked on widest_int, so we are always invoked on wide_int or similar and those have preallocated result sized for the corresponding precision (i.e. BLOCKS_NEEDED (precision)). 2024-02-03 Jakub Jelinek PR middle-end/113722 * wide-int.cc (wi::bswap_large): Rename third argument from len to xlen and adjust use in safe_uhwi. Add len variable, set it to BLOCKS_NEEDED (precision) and use it for clearing of val and as canonize argument. Clear val using memset instead of a loop. * gcc.dg/pr113722.c: New test.=