[llvm] [SandboxVec][LoadStoreVec] Support constant vectors of mixed types (PR #224890)

Vasileios Porpodas via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 21 14:51:30 PDT 2026


================
@@ -82,42 +83,108 @@ LoadInst *LoadStoreVec::createVectorLoad(BndlRef<Instruction *> Loads) {
   return LoadInst::create(Ty, LdPtr, LdAlign, LdWhereIt, *Ctx, "VecIinitL");
 }
 
-Value *LoadStoreVec::createConstantVector(BndlRef<Value *> Operands) {
-  SmallVector<Constant *, 8> Constants;
-  Constants.reserve(Operands.size());
+Constant *LoadStoreVec::createEquivalentConstantWithType(Constant *C,
+                                                         Type *DestTy) {
+  Type *SrcTy = C->getType();
+  if (SrcTy == DestTy)
+    return C;
+  auto IsNonIntegralPtr = [this](Type *Ty) {
+    return Ty->isPointerTy() &&
+           DL->isNonIntegralAddressSpace(Ty->getPointerAddressSpace());
+  };
+  if (IsNonIntegralPtr(SrcTy) || IsNonIntegralPtr(DestTy))
+    return nullptr;
+
+  Constant *AsInt = C;
+  if (!SrcTy->isIntegerTy()) {
+    Type *IntTy = IntegerType::get(*Ctx, Utils::getNumBits(SrcTy, *DL));
+    AsInt = SrcTy->isPointerTy() ? ConstantExpr::getPtrToInt(C, IntTy)
+                                 : ConstantExpr::getBitCast(C, IntTy);
+  }
+  if (DestTy->isIntegerTy())
+    return AsInt;
+  return DestTy->isPointerTy() ? ConstantExpr::getIntToPtr(AsInt, DestTy)
+                               : ConstantExpr::getBitCast(AsInt, DestTy);
+}
+
+Value *LoadStoreVec::createConstantVector(ArrayRef<Value *> Operands,
+                                          Type *LaneTy) {
+  SmallVector<Constant *, 8> ConstantElements;
----------------
vporpo wrote:

nit: Keep this as `Constants` to avoid unnecessary changes in this function.

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


More information about the llvm-commits mailing list