[llvm] Resolving #171877 (PR #172139)
Ron Xavier via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 13 00:47:54 PST 2025
https://github.com/Ronxvier created https://github.com/llvm/llvm-project/pull/172139
Moved constant folding logic from SimplifyLibCalls.cpp to ConstantFoldLibCall2
Meant to resolve #171877
>From ae2549c6b069e998021c1f42080640fa38658b46 Mon Sep 17 00:00:00 2001
From: Ron Xavier <Ronelxavi at gmail.com>
Date: Sat, 13 Dec 2025 03:45:49 -0500
Subject: [PATCH] Resolve #171877
Moved constant folding logic from SimplifyLibCalls.cpp to ConstantFoldLibCall2
---
llvm/lib/Analysis/ConstantFolding.cpp | 12 ++++++++++++
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp | 14 ++------------
2 files changed, 14 insertions(+), 12 deletions(-)
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;
}
//===----------------------------------------------------------------------===//
More information about the llvm-commits
mailing list