Issue 238884
Summary [InstCombine] ldexp folding changes signed and wide exponents
Labels
Assignees
Reporter 0z5a
    InstCombine's `llvm.ldexp` fold matches the exponent as an unsigned `uint64_t` and casts it to `int` before evaluating the scale. This changes the exponent for integer widths other than 32 bits.

```llvm
declare double @llvm.ldexp.f64.i8(double, i8)
declare double @llvm.ldexp.f64.i64(double, i64)

define double @narrow(double %x) {
  %r = call double @llvm.ldexp.f64.i8(double %x, i8 -1)
  ret double %r
}
define double @wide(double %x) {
  %r = call double @llvm.ldexp.f64.i64(double %x, i64 4294967296)
  ret double %r
}
```

`opt -passes=instcombine -S` changes the first scale from 2^-1 to 2^255, and folds the second to `%x` after truncating the exponent to zero. On AArch64, compiling the first function and calling it with 2.0 gives 1.0 at `-O0` but approximately 1.16e77 at `-O2`.

The fold should interpret the APInt as signed and only pass values representable in `scalbn`'s integer argument. For a subnormal scale it must also account for input-denormal flushing; otherwise enabling the fold for narrow negative exponents would introduce another wrong result. The related input-denormal issue is #238186.

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

Reply via email to