[llvm] [SimplifyLibCalls] fdim constant fold (PR #109235)

via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 7 21:10:09 PDT 2024


================
@@ -3109,6 +3109,42 @@ Value *LibCallSimplifier::optimizeRemquo(CallInst *CI, IRBuilderBase &B) {
   return ConstantFP::get(CI->getType(), Rem);
 }
 
+/// Constant folds fdim
+Value *LibCallSimplifier::optimizeFdim(CallInst *CI, IRBuilderBase &B) {
+  // Cannot perform the fold unless the call has attribute memory(none)
+  if (!CI->doesNotAccessMemory())
+    return nullptr;
+
+  const APFloat *X, *Y;
+  // Check if both values are constants
+  if (!match(CI->getArgOperand(0), m_APFloat(X)) ||
----------------
braw-lee wrote:

but this is just a constant fold right?
also `APFloat*` is used later to return NaN values, check status of `fsub` operation
those wouldn't be possible with `Value*`

https://github.com/llvm/llvm-project/pull/109235


More information about the llvm-commits mailing list