[llvm] [LibCallShrinkWrap] Added ilogb in performCallErrors() (PR #122582)
Kshitij Paranjape via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 11 11:38:11 PST 2025
https://github.com/kshitijvp updated https://github.com/llvm/llvm-project/pull/122582
>From 5f29f640f60bb92d6eebbd8eb13a0a6aa967dcb3 Mon Sep 17 00:00:00 2001
From: Kshitij Paranjape <kshitijvparanjape at gmail.com>
Date: Sat, 11 Jan 2025 12:40:23 +0530
Subject: [PATCH 1/3] [LibCallShrinkWrap] Added ilogb in performCallErrors()
ilogb libcall was not being constant folded correctly.
It was due to LibCallShrinkWrap pass not handling
ilogbx, as a result SimplifyCFG pass did not remove
redundant libcall. This patch adds ilogb case in
performCallErrors().
Fixes #101873
---
llvm/lib/Transforms/Utils/LibCallsShrinkWrap.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/llvm/lib/Transforms/Utils/LibCallsShrinkWrap.cpp b/llvm/lib/Transforms/Utils/LibCallsShrinkWrap.cpp
index 9fe655e548c22c..1316137ca4f96b 100644
--- a/llvm/lib/Transforms/Utils/LibCallsShrinkWrap.cpp
+++ b/llvm/lib/Transforms/Utils/LibCallsShrinkWrap.cpp
@@ -246,6 +246,7 @@ bool LibCallsShrinkWrap::performCallErrors(CallInst *CI,
case LibFunc_logb: // Same as log
case LibFunc_logbf: // Same as log
case LibFunc_logbl: // Same as log
+ case LibFunc_ilogb: // Same as log
{
++NumWrappedOneCond;
Cond = createCond(CI, CmpInst::FCMP_OLE, 0.0f);
>From c171c4db0c144fbfc537678ab6f531f908c3522b Mon Sep 17 00:00:00 2001
From: Kshitij Paranjape <kshitijvparanjape at gmail.com>
Date: Sun, 12 Jan 2025 00:26:02 +0530
Subject: [PATCH 2/3] [ConstantFolding] Added ilogb in isMathLibCallNoop()
ilogb libcall was not being constant folded correctly.
This patch adds ilogb with its correct domain in isMathLibCallNoop().
Fixes #101873
---
llvm/lib/Analysis/ConstantFolding.cpp | 3 ++-
llvm/lib/Transforms/Utils/LibCallsShrinkWrap.cpp | 1 -
llvm/test/Transforms/Util/libcalls-shrinkwrap-float.ll | 2 ++
3 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 031d675c330ec4..c1e1f115df16e1 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -3806,7 +3806,8 @@ bool llvm::isMathLibCallNoop(const CallBase *Call,
case LibFunc_log10:
case LibFunc_log10f:
return Op.isNaN() || (!Op.isZero() && !Op.isNegative());
-
+ case LibFunc_ilogb:
+ return !(Op.isNaN()) && !(Op.isZero() || Op.isInfinity());
case LibFunc_expl:
case LibFunc_exp:
case LibFunc_expf:
diff --git a/llvm/lib/Transforms/Utils/LibCallsShrinkWrap.cpp b/llvm/lib/Transforms/Utils/LibCallsShrinkWrap.cpp
index 1316137ca4f96b..9fe655e548c22c 100644
--- a/llvm/lib/Transforms/Utils/LibCallsShrinkWrap.cpp
+++ b/llvm/lib/Transforms/Utils/LibCallsShrinkWrap.cpp
@@ -246,7 +246,6 @@ bool LibCallsShrinkWrap::performCallErrors(CallInst *CI,
case LibFunc_logb: // Same as log
case LibFunc_logbf: // Same as log
case LibFunc_logbl: // Same as log
- case LibFunc_ilogb: // Same as log
{
++NumWrappedOneCond;
Cond = createCond(CI, CmpInst::FCMP_OLE, 0.0f);
diff --git a/llvm/test/Transforms/Util/libcalls-shrinkwrap-float.ll b/llvm/test/Transforms/Util/libcalls-shrinkwrap-float.ll
index f4dc79759d17ed..f1a1c62c51a1db 100644
--- a/llvm/test/Transforms/Util/libcalls-shrinkwrap-float.ll
+++ b/llvm/test/Transforms/Util/libcalls-shrinkwrap-float.ll
@@ -334,6 +334,8 @@ entry:
; CHECK-NEXT: %call_11 = call float @log1pf(float %value)
; CHECK-NEXT: br label %[[END_LABEL]]
; CHECK: [[END_LABEL]]:
+
+ %call_12 = call i32 @ilogb(float %value) strictfp
ret void
}
>From 9c58c9c237c712980f064f498847cf390e2e511e Mon Sep 17 00:00:00 2001
From: Kshitij Paranjape <kshitijvparanjape at gmail.com>
Date: Sun, 12 Jan 2025 01:06:59 +0530
Subject: [PATCH 3/3] added more tests
---
llvm/lib/Analysis/ConstantFolding.cpp | 4 +++-
llvm/test/Transforms/Util/libcalls-shrinkwrap-float.ll | 3 +++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index c1e1f115df16e1..ba61345b5b7c07 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -3806,8 +3806,10 @@ bool llvm::isMathLibCallNoop(const CallBase *Call,
case LibFunc_log10:
case LibFunc_log10f:
return Op.isNaN() || (!Op.isZero() && !Op.isNegative());
+
case LibFunc_ilogb:
- return !(Op.isNaN()) && !(Op.isZero() || Op.isInfinity());
+ return !Op.isNaN() && (!Op.isZero() && !Op.isInfinity());
+
case LibFunc_expl:
case LibFunc_exp:
case LibFunc_expf:
diff --git a/llvm/test/Transforms/Util/libcalls-shrinkwrap-float.ll b/llvm/test/Transforms/Util/libcalls-shrinkwrap-float.ll
index f1a1c62c51a1db..8c9af686c706fa 100644
--- a/llvm/test/Transforms/Util/libcalls-shrinkwrap-float.ll
+++ b/llvm/test/Transforms/Util/libcalls-shrinkwrap-float.ll
@@ -223,6 +223,8 @@ entry:
; CHECK-NEXT: %call_11 = call float @log1pf(float %value)
; CHECK-NEXT: br label %[[END_LABEL]]
; CHECK: [[END_LABEL]]:
+
+ %call_12 = call i32 @ilogb(float %value)
ret void
}
@@ -351,5 +353,6 @@ declare float @log10f(float)
declare float @log2f(float)
declare float @logbf(float)
declare float @log1pf(float)
+declare i32 @ilogb(float)
; CHECK: ![[BRANCH_WEIGHT]] = !{!"branch_weights", i32 1, i32 1048575}
More information about the llvm-commits
mailing list