Skip to content

Commit b446f90

Browse files
authored
SimplifyLibCalls: Don't require ldexp to emit intrinsic in pow combine (#95277)
Do not require a libm ldexp libcall to emit the ldexp intrinsic when transforming pow(2, x) -> ldexp(1, x) This enables the half intrinsic case to fold.
1 parent f5a93c5 commit b446f90

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2092,7 +2092,11 @@ Value *LibCallSimplifier::replacePowWithExp(CallInst *Pow, IRBuilderBase &B) {
20922092
// pow(2.0, itofp(x)) -> ldexp(1.0, x)
20932093
if ((UseIntrinsic || !Ty->isVectorTy()) && match(Base, m_SpecificFP(2.0)) &&
20942094
(isa<SIToFPInst>(Expo) || isa<UIToFPInst>(Expo)) &&
2095-
hasFloatFn(M, TLI, Ty, LibFunc_ldexp, LibFunc_ldexpf, LibFunc_ldexpl)) {
2095+
(UseIntrinsic ||
2096+
hasFloatFn(M, TLI, Ty, LibFunc_ldexp, LibFunc_ldexpf, LibFunc_ldexpl))) {
2097+
2098+
// TODO: Shouldn't really need to depend on getIntToFPVal for intrinsic. Can
2099+
// just directly use the original integer type.
20962100
if (Value *ExpoI = getIntToFPVal(Expo, B, TLI->getIntSize())) {
20972101
Constant *One = ConstantFP::get(Ty, 1.0);
20982102

llvm/test/Transforms/InstCombine/pow-to-ldexp.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ define double @pow_sitofp_f64_const_base_2(i32 %x) {
116116
define half @pow_sitofp_f16_const_base_2(i32 %x) {
117117
; CHECK-LABEL: define half @pow_sitofp_f16_const_base_2(
118118
; CHECK-SAME: i32 [[X:%.*]]) {
119-
; CHECK-NEXT: [[ITOFP:%.*]] = sitofp i32 [[X]] to half
120-
; CHECK-NEXT: [[POW:%.*]] = tail call half @llvm.pow.f16(half 0xH4000, half [[ITOFP]])
119+
; CHECK-NEXT: [[POW:%.*]] = tail call half @llvm.ldexp.f16.i32(half 0xH3C00, i32 [[X]])
121120
; CHECK-NEXT: ret half [[POW]]
122121
;
123122
%itofp = sitofp i32 %x to half

0 commit comments

Comments
 (0)