[llvm] [SimplifyLibCalls] fdim constant fold (PR #109235)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 8 14:02:09 PDT 2024
================
@@ -3109,6 +3109,52 @@ 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;
+
+ // propogate poison/undef if any
+ if (match(CI->getArgOperand(0), m_Undef()))
+ return CI->getArgOperand(0);
+ if (match(CI->getArgOperand(1), m_Undef()))
+ return CI->getArgOperand(1);
----------------
arsenm wrote:
This isn't quite right. You can propagate poison -> poison, but undef needs more constraints (usually undef gets folded to qnan)
https://github.com/llvm/llvm-project/pull/109235
More information about the llvm-commits
mailing list