[flang-commits] [flang] [llvm] [flang] Fix wrong result for exponentiation when denormal is expected (PR #205262)

via flang-commits flang-commits at lists.llvm.org
Fri Oct 9 05:11:19 PDT 2026


ejose02 wrote:

> (This comment was generated with the help of AI)
> 
> The description says the rule is applied in the runtime `FPowI`, but by default `x**n` with a non-constant exponent doesn't call it:
> 
> ```fortran
> subroutine s(x, n, y)
>   real :: x, y
>   integer :: n
>   y = x**n
> end
> ```
> 
> ```
> $ flang -O2 -S -emit-llvm -o - s.f90 | grep -oE 'llvm\.powi[.a-z0-9]*|_FortranAFPow[0-9a-z]+' | sort -u
> llvm.powi.f32.i32
> $ flang -O2 -mllvm -math-runtime=precise -S -emit-llvm -o - s.f90 | grep -oE 'llvm\.powi[.a-z0-9]*|_FortranAFPow[0-9a-z]+' | sort -u
> _FortranAFPow4i
> ```
> 
> `-O0` lowers the same way, so in a default build `x**n` with `x = 2.0` and `n = -133` still evaluates to zero. Please say in the description which paths this fixes: constant folding, and the runtime only under `-math-runtime=precise`.

Done. I have updated the description

https://github.com/llvm/llvm-project/pull/205262


More information about the flang-commits mailing list