[all-commits] [llvm/llvm-project] 08e6e1: [GlobalISel] Fix sign-extended byte mask in lowerB...

Ilpo Ruotsalainen via All-commits all-commits at lists.llvm.org
Fri Jun 12 18:41:58 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 08e6e1476b4d3273f95ef715391154be0a6881bc
      https://github.com/llvm/llvm-project/commit/08e6e1476b4d3273f95ef715391154be0a6881bc
  Author: Ilpo Ruotsalainen <lonewolf at iki.fi>
  Date:   2026-06-13 (Sat, 13 Jun 2026)

  Changed paths:
    M llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
    M llvm/test/CodeGen/RISCV/GlobalISel/legalizer/legalize-bitreverse-rv64.mir
    M llvm/test/CodeGen/RISCV/GlobalISel/legalizer/legalize-bswap-rv64.mir
    M llvm/test/CodeGen/RISCV/GlobalISel/rv64zbb.ll
    M llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp

  Log Message:
  -----------
  [GlobalISel] Fix sign-extended byte mask in lowerBswap (#199387)

The per-byte mask in `LegalizerHelper::lowerBswap` was constructed via

```
APInt APMask(SizeInBytes * 8, 0xFF << (i * 8));
```

where `0xFF << (i * 8)` is evaluated as a signed `int`. For `i*8 >= 24`
(byte-3 mask of an s64 G_BSWAP) the value `0xFF000000` does not fit in a
positive 32-bit `int`; the conversion to signed `int` is
implementation-defined under C++17 (UB under C++11, fully defined under
C++20) and on two's-complement targets produces `-16777216`. The modular
conversion to `uint64_t` in the `APInt` constructor then materializes
that negative `int` as `0xFFFFFFFFFF000000` — the intended mask was
`0x00000000FF000000`. The over-wide mask preserved bytes 4-7 of the
source where only byte 3 was intended, and the spurious bytes propagated
through the subsequent shift/OR chain.

Use `APInt::getBitsSet` to construct the mask, matching the file's other
bit-range mask constructions.

Fixes #199386



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list