Issue 244637
Summary [ConstantFolding] constrained fpext of a constant is not folded under -frounding-math
Labels new issue
Assignees
Reporter shalseth
    With `-frounding-math`, an `fpext` of a constant stays a runtime `llvm.experimental.constrained.fpext` call, even with `fpexcept.ignore`. The extension is exact in every rounding mode, so it can be folded. On targets with a soft `fp128` the call becomes a libcall. On sparc64 that is `_Qp_dtoq` or `_Qp_stoq`.

```c
long double qnan (void) { return __builtin_nanf (""); }
long double ten (void) { double d = 10.0; return d; }
```

```
$ clang -O2 -frounding-math -S -emit-llvm t.c -o - | grep 'tail call'
  %conv = tail call fp128 @llvm.experimental.constrained.fpext.f128.f32(float +qnan, metadata !"fpexcept.ignore") #2
  %conv = tail call fp128 @llvm.experimental.constrained.fpext.f128.f64(double 1.000000e+01, metadata !"fpexcept.ignore") #2
$ clang -O2 -frounding-math -S t.c -o - | grep call
	call _Qp_stoq
	call _Qp_dtoq
```

Without `-frounding-math` both functions load a constant. GCC loads a constant with or without it. The same happens with `x86_fp80` on x86_64, and with plain `opt`:

```llvm
define double @f() strictfp {
  %r = call double @llvm.experimental.constrained.fpext.f64.f32(float 1.0, metadata !"fpexcept.ignore") strictfp
  ret double %r
}
```

`opt -O2` leaves the call in place. `ConstantFolding.cpp` handles the constrained arithmetic, compare and rounding intrinsics, but not `constrained_fpext`.

glibc builds libc with `-frounding-math`. A clang-built sparc64 libc.so therefore calls `_Qp_dtoq` and `_Qp_stoq` in `strtold`, `qecvt_r` and `__strtold_nan`, where the GCC build uses constants. This is one reason glibc's elf/check-localplt test fails with clang (https://github.com/sparclinux/issues/issues/96).

LLVM main 1ed0efd70af1, SPARC M7, Linux sparc64.

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

Reply via email to