[llvm] [SimplifyLibCalls] Constant fold `remquo` (PR #99647)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 22 03:33:06 PDT 2024


================
@@ -3018,6 +3018,39 @@ void LibCallSimplifier::classifyArgUse(
   }
 }
 
+/// Constant folds remquo
+Value *LibCallSimplifier::optimizeRemquo(CallInst *CI, IRBuilderBase &B) {
+  const APFloat *X, *Y;
+  if (!match(CI->getArgOperand(0), m_APFloat(X)) ||
+      !match(CI->getArgOperand(1), m_APFloat(Y)))
+    return nullptr;
+
+  if (X->isNaN() || Y->isNaN() || X->isInfinity() || Y->isZero())
+    return nullptr;
----------------
dtcxzyw wrote:

See https://en.cppreference.com/w/cpp/numeric/math/remquo:
> If the implementation supports IEEE floating-point arithmetic (IEC 60559),
The current [rounding mode](https://en.cppreference.com/w/cpp/numeric/fenv/FE_round) has no effect.
[FE_INEXACT](https://en.cppreference.com/w/cpp/numeric/fenv/FE_exceptions) is never raised.
If x is ±∞ and y is not NaN, NaN is returned and [FE_INVALID](https://en.cppreference.com/w/cpp/numeric/fenv/FE_exceptions) is raised.
If y is ±0 and x is not NaN, NaN is returned and [FE_INVALID](https://en.cppreference.com/w/cpp/numeric/fenv/FE_exceptions) is raised.
If either x or y is NaN, NaN is returned.

IIRC llvm shouldn't convert these invalid calls into fp exceptions.



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


More information about the llvm-commits mailing list