[all-commits] [llvm/llvm-project] 1e5ebb: [InstCombine] Fold exp2(uitofp x) to ldexp(1.0, x)...
Harrison Hao via All-commits
all-commits at lists.llvm.org
Wed Sep 30 10:55:42 PDT 2026
Branch: refs/heads/users/harrisonGPU/instcombine/exp2-to-ldexp
Home: https://github.com/llvm/llvm-project
Commit: 1e5ebb6546e7a04133dcc07ab7d2541b2a7a550a
https://github.com/llvm/llvm-project/commit/1e5ebb6546e7a04133dcc07ab7d2541b2a7a550a
Author: Harrison Hao <tsworld1314 at gmail.com>
Date: 2026-10-01 (Thu, 01 Oct 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-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.
Commit: a68a8f9222cb235274fbcb69364326d522fe6acc
https://github.com/llvm/llvm-project/commit/a68a8f9222cb235274fbcb69364326d522fe6acc
Author: Harrison Hao <tsworld1314 at gmail.com>
Date: 2026-10-01 (Thu, 01 Oct 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
Log Message:
-----------
Update for comments
Compare: https://github.com/llvm/llvm-project/compare/3cc13c858ff0...a68a8f9222cb
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