Skip to content

Commit d07e70b

Browse files
committed
[SimplifyLibCalls] Add f128 type for merging sqrt into the power of exp
1 parent a3a9ba8 commit d07e70b

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2720,6 +2720,9 @@ Value *LibCallSimplifier::mergeSqrtToExp(CallInst *CI, IRBuilderBase &B) {
27202720
ExpLb = LibFunc_exp;
27212721
Exp2Lb = LibFunc_exp2;
27222722
Exp10Lb = LibFunc_exp10;
2723+
} else if (CI->getType()->getScalarType()->isFP128Ty()) {
2724+
ExpLb = LibFunc_expl;
2725+
Exp2Lb = LibFunc_exp2l;
27232726
} else
27242727
return nullptr;
27252728
} else

llvm/test/Transforms/InstCombine/sqrt.ll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,25 @@ define <2 x float> @sqrt_exp_vec(<2 x float> %x) {
201201
ret <2 x float> %res
202202
}
203203

204+
define dso_local fp128 @sqrt_exp_long_double(fp128 %x, fp128 %y) {
205+
; CHECK-LABEL: @sqrt_exp_long_double(
206+
; CHECK-NEXT: entry:
207+
; CHECK-NEXT: [[MERGED_SQRT:%.*]] = fmul fast fp128 [[X:%.*]], 0xL00000000000000003FFE000000000000
208+
; CHECK-NEXT: [[TMP0:%.*]] = call fast fp128 @llvm.exp.f128(fp128 [[MERGED_SQRT]])
209+
; CHECK-NEXT: [[MERGED_SQRT1:%.*]] = fmul fast fp128 [[Y:%.*]], 0xL00000000000000003FFE000000000000
210+
; CHECK-NEXT: [[TMP1:%.*]] = call fast fp128 @llvm.exp2.f128(fp128 [[MERGED_SQRT1]])
211+
; CHECK-NEXT: [[ADD:%.*]] = fadd fast fp128 [[TMP0]], [[TMP1]]
212+
; CHECK-NEXT: ret fp128 [[ADD]]
213+
;
214+
entry:
215+
%0 = call fast fp128 @llvm.exp.f128(fp128 %x)
216+
%1 = call fast fp128 @llvm.sqrt.f128(fp128 %0)
217+
%2 = call fast fp128 @llvm.exp2.f128(fp128 %y)
218+
%3 = call fast fp128 @llvm.sqrt.f128(fp128 %2)
219+
%add = fadd fast fp128 %1, %3
220+
ret fp128 %add
221+
}
222+
204223
declare i32 @foo(double)
205224
declare double @sqrt(double) readnone
206225
declare float @sqrtf(float)
@@ -212,3 +231,6 @@ declare double @exp2(double)
212231
declare double @exp10(double)
213232
declare <2 x float> @llvm.exp.v2f32(<2 x float>)
214233
declare <2 x float> @llvm.sqrt.v2f32(<2 x float>)
234+
declare fp128 @llvm.exp.f128(fp128)
235+
declare fp128 @llvm.sqrt.f128(fp128)
236+
declare fp128 @llvm.exp2.f128(fp128)

0 commit comments

Comments
 (0)