[llvm] [LLVM] Add constant folding for llrint, llrintf, llrintl (PR #154799)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 22 08:11:21 PDT 2025


================
@@ -3109,6 +3109,29 @@ Value *LibCallSimplifier::optimizeRemquo(CallInst *CI, IRBuilderBase &B) {
   return ConstantFP::get(CI->getType(), Rem);
 }
 
+
+Value *LibCallSimplifier::optimizellrint(CallInst *CI,IRBuilderBase &B){
+  const APFloat *X;
+  if(!match(CI->getOperand(0),m_APFloat(X))){
+    return nullptr;
+  }
+  Type *type=CI->getType();
+
+  unsigned width=type->getIntegerBitWidth();
+
+  APSInt Result(width,false);
+  bool Isexact;
+
+  APFloat::opStatus Status=X->convertToInteger(Result,APFloat::rmNearestTiesToEven,&Isexact);
+
+  if(Status==APFloat::opOK || Status==APFloat::opInexact){
+    return ConstantInt::get(type,Result);
+  }
+
+  return nullptr;
+
+}
----------------
arsenm wrote:

Still belongs in ConstantFolding

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


More information about the llvm-commits mailing list