[llvm] Create a 128 bit floating point constant from 2 64 bit values (PR #164381)

peter mckinna via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 21 02:47:30 PDT 2025


https://github.com/demoitem created https://github.com/llvm/llvm-project/pull/164381

This change adds the ability to create a 128 bit floating point value from 2 64 bit integer values.
Some language frontends have already parsed a floating point string into a proper 128 bit quad value
and need to get the llvm value directly.

>From 624b310dc7325933e197e7b0218e9b353328d1a7 Mon Sep 17 00:00:00 2001
From: peter mckinna <peter.mckinna at gmail.com>
Date: Tue, 21 Oct 2025 20:31:25 +1100
Subject: [PATCH] Create a 128 bit floating point constant from 2 64 bit values

---
 llvm/include/llvm-c/Core.h | 7 +++++++
 llvm/lib/IR/Core.cpp       | 7 +++++++
 2 files changed, 14 insertions(+)

diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h
index 4e380d9bd5969..c2f68ce2219ba 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-c/Core.h
@@ -2339,6 +2339,13 @@ LLVM_C_ABI LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy,
                                                      const char *Text,
                                                      unsigned SLen);
 
+/**
+ * Obtain a constant for a floating point FP128 value from 2 64 bit values.
+ * (112 bit mantissa)
+ */
+
+LLVMValueRef LLVMConstFP128(LLVMContextRef C, const uint64_t N[2]);
+
 /**
  * Obtain the zero extended value for an integer constant value.
  *
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index 27d8294b01264..6246880f0bec4 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -1573,6 +1573,13 @@ LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char Str[],
   return wrap(ConstantFP::get(unwrap(RealTy), StringRef(Str, SLen)));
 }
 
+LLVMValueRef LLVMConstFP128(LLVMContextRef C, const uint64_t N[2]) {
+  Type *Ty = Type::getFP128Ty(*unwrap(C));
+  APInt AI(128, ArrayRef<uint64_t>(N, 2));
+  APFloat Quad(APFloat::IEEEquad(), AI);
+  return wrap(ConstantFP::get(Ty, Quad));
+}
+
 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal) {
   return unwrap<ConstantInt>(ConstantVal)->getZExtValue();
 }



More information about the llvm-commits mailing list