[all-commits] [llvm/llvm-project] 764b6c: [InstCombine] Fold exp2(uitofp x) to ldexp(1.0, x)...

Harrison Hao via All-commits all-commits at lists.llvm.org
Tue Sep 29 09:44:15 PDT 2026


  Branch: refs/heads/users/harrisonGPU/instcombine/exp2-to-ldexp
  Home:   https://github.com/llvm/llvm-project
  Commit: 764b6cb449da7848de333381e4d2be9073300de5
      https://github.com/llvm/llvm-project/commit/764b6cb449da7848de333381e4d2be9073300de5
  Author: Harrison Hao <tsworld1314 at gmail.com>
  Date:   2026-09-30 (Wed, 30 Sep 2026)

  Changed paths:
    M llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
    M llvm/test/Transforms/InstCombine/exp2-1.ll
    M llvm/test/Transforms/InstCombine/exp2-to-ldexp.ll
    M llvm/test/Transforms/InstCombine/pow_fp_int.ll
    M llvm/test/Transforms/InstCombine/pow_fp_int16.ll

  Log Message:
  -----------
  [InstCombine] Fold exp2(uitofp x) to ldexp(1.0, x) with ninf

`exp2(uitofp iN x) -> ldexp(1.0, zext x)` currently requires N to be
narrower than `int`, because `ldexp` takes a signed `int` exponent.
When N equals the width of `int`, the fold is still correct under `ninf`.
Every LLVM FP type has $E_{\max} \le 16383 < 2^{15} \le 2^{N-1}$, so:

- $x < 2^{N-1}$: signed and unsigned $x$ agree, so $\operatorname{ldexp}(1.0, x) = 2^{x} = \operatorname{exp2}(x)$.
- $x \ge 2^{N-1}$: $\operatorname{exp2}(x) \ge 2^{2^{N-1}} > 2^{E_{\max}}$ overflows to $+\infty$, which is poison under `ninf`.

This only applies to the intrinsic, since the `exp2` libcall may set
`errno` on overflow.

This also enables `pow(2.0, uitofp x) -> ldexp` via the existing
`pow(2^n, x) -> exp2(n * x)` fold.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list