[llvm] b446f90 - SimplifyLibCalls: Don't require ldexp to emit intrinsic in pow combine (#95277)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 13 01:11:22 PDT 2024


Author: Matt Arsenault
Date: 2024-06-13T10:11:18+02:00
New Revision: b446f9079bdc1123e1aafe5a535d8dbea835d8e8

URL: https://github.com/llvm/llvm-project/commit/b446f9079bdc1123e1aafe5a535d8dbea835d8e8
DIFF: https://github.com/llvm/llvm-project/commit/b446f9079bdc1123e1aafe5a535d8dbea835d8e8.diff

LOG: 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.

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
    llvm/test/Transforms/InstCombine/pow-to-ldexp.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index a91c3ff930616..125e5fa437538 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -2092,7 +2092,11 @@ Value *LibCallSimplifier::replacePowWithExp(CallInst *Pow, IRBuilderBase &B) {
   // pow(2.0, itofp(x)) -> ldexp(1.0, x)
   if ((UseIntrinsic || !Ty->isVectorTy()) && match(Base, m_SpecificFP(2.0)) &&
       (isa<SIToFPInst>(Expo) || isa<UIToFPInst>(Expo)) &&
-      hasFloatFn(M, TLI, Ty, LibFunc_ldexp, LibFunc_ldexpf, LibFunc_ldexpl)) {
+      (UseIntrinsic ||
+       hasFloatFn(M, TLI, Ty, LibFunc_ldexp, LibFunc_ldexpf, LibFunc_ldexpl))) {
+
+    // TODO: Shouldn't really need to depend on getIntToFPVal for intrinsic. Can
+    // just directly use the original integer type.
     if (Value *ExpoI = getIntToFPVal(Expo, B, TLI->getIntSize())) {
       Constant *One = ConstantFP::get(Ty, 1.0);
 

diff  --git a/llvm/test/Transforms/InstCombine/pow-to-ldexp.ll b/llvm/test/Transforms/InstCombine/pow-to-ldexp.ll
index cb51e92093263..d31b7c9fe2835 100644
--- a/llvm/test/Transforms/InstCombine/pow-to-ldexp.ll
+++ b/llvm/test/Transforms/InstCombine/pow-to-ldexp.ll
@@ -116,8 +116,7 @@ define double @pow_sitofp_f64_const_base_2(i32 %x) {
 define half @pow_sitofp_f16_const_base_2(i32 %x) {
 ; CHECK-LABEL: define half @pow_sitofp_f16_const_base_2(
 ; CHECK-SAME: i32 [[X:%.*]]) {
-; CHECK-NEXT:    [[ITOFP:%.*]] = sitofp i32 [[X]] to half
-; CHECK-NEXT:    [[POW:%.*]] = tail call half @llvm.pow.f16(half 0xH4000, half [[ITOFP]])
+; CHECK-NEXT:    [[POW:%.*]] = tail call half @llvm.ldexp.f16.i32(half 0xH3C00, i32 [[X]])
 ; CHECK-NEXT:    ret half [[POW]]
 ;
   %itofp = sitofp i32 %x to half


        


More information about the llvm-commits mailing list