]> git.ipfire.org Git - thirdparty/gcc.git/commit
bitint: Zero-extend the result of a signed->unsigned widening cast
authorYang Yujie <yangyujie@loongson.cn>
Wed, 6 Aug 2025 10:03:39 +0000 (12:03 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 6 Aug 2025 10:03:39 +0000 (12:03 +0200)
commit94d2bc6d08caad947a8897a538f2a9b64e16a11a
tree415710c9994d02a32c4ee1ce493fec1457909861
parent88f638e276c25e216b3d01c0d7aa25a0d17921d9
bitint: Zero-extend the result of a signed->unsigned widening cast

A widening cast from a signed _BitInt operand to an unsigned _BitInt
type involves filling the extra limb(s) with sign extension.
On a target that wants _BitInts extended in memory, if this unsigned
type has a partial limb, the unused part of it should be zeroed.

e.g. Assuming limb_mode == E_DImode, at the end of

  void
  test (unsigned _BitInt(519) *t, _BitInt(512) x)
  {
    *t = -x;
  }

the most significant limb of *t should be masked with 0x7f.

This patch also fixes gcc.dg/torture/bitint-16.c, which aborts at -O2
when the extension on load is optimized away.

* gimple-lower-bitint.cc (bitint_large_huge::lower_mergeable_stmt):
Zero-extend the partial limb of any unsigned _BitInt LHS assigned
with a widening sign-extension.

* gcc.dg/torture/bitint-83.c: New test.
gcc/gimple-lower-bitint.cc
gcc/testsuite/gcc.dg/torture/bitint-83.c [new file with mode: 0644]