| Issue |
233316
|
| Summary |
[Attributor] Load of a `half` store as `bfloat` is folded to the `fptrunc` of the stored value instead of its bits
|
| Labels |
miscompilation,
llvm::Attributor,
generated by fuzzer
|
| Assignees |
|
| Reporter |
ChoKyuWon
|
### reproducer
godbolt: https://godbolt.org/z/sr137fnKq
alive: https://alive2.llvm.org/ce/z/NC7S3E
```llvm
define bfloat @f() {
%p = alloca half, align 2
store half 0xH3C01, ptr %p, align 2
%l = load bfloat, ptr %p, align 2
ret bfloat %l
}
```
```console
$ opt -passes=attributor -S repro.ll
define noundef nofpclass(nan inf zero sub nnorm) bfloat @f() #0 {
ret bfloat 1.000000e+00
}
$ alive-tv --disable-undef-input --disable-poison-input --passes=attributor repro.ll
Transformation doesn't verify!
ERROR: Value mismatch
Source value: #x3c01 (0.007873535156?)
Target value: #x3f80 (1)
```
### suggested fix
`AA::getWithType` (Attributor.cpp) gives a forwarded stored constant the load's type, so it must reinterpret the bits, but its FP-to-FP branch does `ConstantFoldCastInstruction(Instruction::FPTrunc, C, &Ty)`.
The `>=` size gate lets two same-width FP types (`half`/`bfloat`) reach it, where `fptrunc` is not even a valid cast; use a bitcast for equal widths (or bail out) instead.
> Disclaimer: This test case was generated by a fuzzer, and the report was written with LLM assistance.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs