[llvm] Resolving #171877 (PR #172139)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 13 00:48:40 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Ron Xavier (Ronxvier)
<details>
<summary>Changes</summary>
Moved constant folding logic from SimplifyLibCalls.cpp to ConstantFoldLibCall2
Meant to resolve #<!-- -->171877
---
Full diff: https://github.com/llvm/llvm-project/pull/172139.diff
2 Files Affected:
- (modified) llvm/lib/Analysis/ConstantFolding.cpp (+12)
- (modified) llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp (+2-12)
``````````diff
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index a9b51065a1d99..8a73c02bc363e 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -3241,6 +3241,18 @@ static Constant *ConstantFoldLibCall2(StringRef Name, Type *Ty,
if (TLI->has(Func))
return ConstantFoldBinaryFP(atan2, Op1V, Op2V, Ty);
break;
+ case LibFunc_fdim:
+ case LibFunc_fdimf:
+ case LibFunc_fdiml:
+ if (TLI->has(Func)){
+ APFloat Difference = Op1V;
+ Difference.subtract(Op2V, RoundingMode::NearestTiesToEven);
+
+ APFloat MaxVal =
+ maximum(Difference, APFloat::getZero(Ty->getFltSemantics()));
+ return ConstantFP::get(Ty->getContext(), MaxVal);
+ }
+ break;
}
return nullptr;
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index c3537f544c432..55cd08b3de855 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -3201,18 +3201,8 @@ Value *LibCallSimplifier::optimizeFdim(CallInst *CI, IRBuilderBase &B) {
if (isa<PoisonValue>(CI->getArgOperand(1)))
return CI->getArgOperand(1);
- const APFloat *X, *Y;
- // Check if both values are constants
- if (!match(CI->getArgOperand(0), m_APFloat(X)) ||
- !match(CI->getArgOperand(1), m_APFloat(Y)))
- return nullptr;
-
- APFloat Difference = *X;
- Difference.subtract(*Y, RoundingMode::NearestTiesToEven);
-
- APFloat MaxVal =
- maximum(Difference, APFloat::getZero(CI->getType()->getFltSemantics()));
- return ConstantFP::get(CI->getType(), MaxVal);
+ // Constant folding will be handled by ConstantFoldLibCall2
+ return nullptr;
}
//===----------------------------------------------------------------------===//
``````````
</details>
https://github.com/llvm/llvm-project/pull/172139
More information about the llvm-commits
mailing list