[llvm] [LLVM][ExecutionEngine] Add vector ConstantInt/FP support to getConstantValue(). (PR #182538)

Paul Walker via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 20 09:02:26 PST 2026


https://github.com/paulwalker-arm created https://github.com/llvm/llvm-project/pull/182538

None

>From 09d1d2d43d10b15ae61817b84e8011986e06d6ed Mon Sep 17 00:00:00 2001
From: Paul Walker <paul.walker at arm.com>
Date: Fri, 20 Feb 2026 13:45:48 +0000
Subject: [PATCH 1/2] Add test showing crash when vector ConstantInt/FP are in
 use.

---
 .../Interpreter/test-interp-vec-insertelement.ll               | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/llvm/test/ExecutionEngine/Interpreter/test-interp-vec-insertelement.ll b/llvm/test/ExecutionEngine/Interpreter/test-interp-vec-insertelement.ll
index a6698e60fc3a0..35e23c61f9ec1 100644
--- a/llvm/test/ExecutionEngine/Interpreter/test-interp-vec-insertelement.ll
+++ b/llvm/test/ExecutionEngine/Interpreter/test-interp-vec-insertelement.ll
@@ -1,4 +1,5 @@
  ; RUN: %lli -jit-kind=mcjit -force-interpreter=true %s > /dev/null
+ ; RUN: %lli -jit-kind=mcjit -force-interpreter=true -use-constant-int-for-fixed-length-splat -use-constant-fp-for-fixed-length-splat %s > /dev/null
 
 define i32 @main() {
  %v0 = insertelement <2 x i8> zeroinitializer, i8 1, i32 1
@@ -37,5 +38,7 @@ define i32 @main() {
  %v28 = insertelement <8 x double> zeroinitializer, double 4.0, i32 4
  %v29 = insertelement <16 x double> zeroinitializer, double 5.0, i32 7
 
+ %v30 = insertelement <16 x i64> splat(i64 1), i64 5, i32 7
+ %v31 = insertelement <16 x double> splat(double 1.0), double 5.0, i32 7
  ret i32 0
 }

>From ec2a94e56e581f7453c31c1e2caa36fdba4255f6 Mon Sep 17 00:00:00 2001
From: Paul Walker <paul.walker at arm.com>
Date: Fri, 20 Feb 2026 14:25:36 +0000
Subject: [PATCH 2/2] [LLVM][ExecutionEngine] Add vector ConstantInt/FP support
 to getConstantValue().

---
 llvm/lib/ExecutionEngine/ExecutionEngine.cpp | 31 +++++++++++---------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/llvm/lib/ExecutionEngine/ExecutionEngine.cpp b/llvm/lib/ExecutionEngine/ExecutionEngine.cpp
index 38aed020bb119..9eb9d0b5314f7 100644
--- a/llvm/lib/ExecutionEngine/ExecutionEngine.cpp
+++ b/llvm/lib/ExecutionEngine/ExecutionEngine.cpp
@@ -934,25 +934,27 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
     const ConstantDataVector *CDV = dyn_cast<ConstantDataVector>(C);
     const ConstantVector *CV = dyn_cast<ConstantVector>(C);
     const ConstantAggregateZero *CAZ = dyn_cast<ConstantAggregateZero>(C);
+    const ConstantInt *CI = dyn_cast<ConstantInt>(C);
+    const ConstantFP *CFP = dyn_cast<ConstantFP>(C);
 
     if (CDV) {
         elemNum = CDV->getNumElements();
         ElemTy = CDV->getElementType();
-    } else if (CV || CAZ) {
+    } else if (CV || CAZ || CI || CFP) {
       auto *VTy = cast<FixedVectorType>(C->getType());
       elemNum = VTy->getNumElements();
       ElemTy = VTy->getElementType();
     } else {
-        llvm_unreachable("Unknown constant vector type!");
+      llvm_unreachable("Unknown constant vector type!");
     }
 
     Result.AggregateVal.resize(elemNum);
     // Check if vector holds floats.
     if(ElemTy->isFloatTy()) {
-      if (CAZ) {
-        GenericValue floatZero;
-        floatZero.FloatVal = 0.f;
-        llvm::fill(Result.AggregateVal, floatZero);
+      if (CAZ || CFP) {
+        GenericValue floatVal;
+        floatVal.FloatVal = CAZ ? 0.f : CFP->getValueAPF().convertToFloat();
+        llvm::fill(Result.AggregateVal, floatVal);
         break;
       }
       if(CV) {
@@ -970,10 +972,10 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
     }
     // Check if vector holds doubles.
     if (ElemTy->isDoubleTy()) {
-      if (CAZ) {
-        GenericValue doubleZero;
-        doubleZero.DoubleVal = 0.0;
-        llvm::fill(Result.AggregateVal, doubleZero);
+      if (CAZ || CFP) {
+        GenericValue doubleVal;
+        doubleVal.DoubleVal = CAZ ? 0.0 : CFP->getValueAPF().convertToDouble();
+        llvm::fill(Result.AggregateVal, doubleVal);
         break;
       }
       if(CV) {
@@ -991,10 +993,11 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
     }
     // Check if vector holds integers.
     if (ElemTy->isIntegerTy()) {
-      if (CAZ) {
-        GenericValue intZero;
-        intZero.IntVal = APInt(ElemTy->getScalarSizeInBits(), 0ull);
-        llvm::fill(Result.AggregateVal, intZero);
+      if (CAZ || CI) {
+        GenericValue intVal;
+        intVal.IntVal =
+            CAZ ? APInt(ElemTy->getScalarSizeInBits(), 0ull) : CI->getValue();
+        llvm::fill(Result.AggregateVal, intVal);
         break;
       }
       if(CV) {



More information about the llvm-commits mailing list