Issue 244518
Summary [SelectionDAG] Assertion "Invalid use of small shift amount with oversized value!" when a narrow bit-field read is zero-extended to i512 (`_BitInt(512)`)
Labels new issue
Assignees
Reporter haoxintu
    ## Description

```c
struct S
{
 _BitInt(33) : 8;
  unsigned b : 1;
};

_BitInt(512)
f (struct S *s)
{
 return s->b;
}
```

```
$ clang -O0 -c repro.c      # also -O1, -O2, -O3, -Os
clang: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:8894: llvm::SDValue llvm::SelectionDAG::getNode(...):
Assertion `N2.getValueType().getScalarSizeInBits() >= Log2_32_Ceil(VT.getScalarSizeInBits()) && "Invalid use of small shift amount with oversized value!"' failed.
...
4.	Running pass 'X86 DAG->DAG Instruction Selection' on function '@f'
```

The same assertion fires in llc alone, at -O0 and -O2:

```llvm
define void @f(ptr %out, ptr %p) {
 %v = load i16, ptr %p, align 4
  %s = lshr i16 %v, 8
  %b = and i16 %s, 1
 %w = zext i16 %b to i512
  store i512 %w, ptr %out, align 8
  ret void
}
```

The bit-field read becomes `zext (and (lshr i16 %v, 8), 1)` to i512. The DAG apparently rebuilds the shift in i512 while keeping the i8 shift-amount type of the narrow shift. An i8 shift amount cannot address 512 bits; that needs `Log2_32_Ceil(512) = 9` bits.

At -O0 the same assertion is also reached without a bit-field:

```c
_BitInt(512) g (unsigned long long e) { return (e >> 4) & 1; }
```

Reproduced in Godbolt (x86-64 clang assertions trunk, -O0): https://godbolt.org/z/5azG1o7av

## Checked versions

- Assertion at every -O level with clang trunk 2012344e5da8 (2026-11-19).

- clang 21.1.8 (release build, no assertions) compiles it.

Thanks.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to