From 2a725d2faa29bc3485be785bb56ec144de3fe2e1 Mon Sep 17 00:00:00 2001 From: Ben Ashbaugh Date: Sun, 29 Dec 2024 14:43:31 -0800 Subject: [PATCH] handle more vector types Even though we only expect to OpBitcast a pointer to a vector of two 32-bit integers, it's easy enough to just handle all vector types. --- lib/SPIRV/SPIRVReader.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/SPIRV/SPIRVReader.cpp b/lib/SPIRV/SPIRVReader.cpp index 21cbf0fbd..b51771fbc 100644 --- a/lib/SPIRV/SPIRVReader.cpp +++ b/lib/SPIRV/SPIRVReader.cpp @@ -1089,28 +1089,28 @@ Value *SPIRVToLLVM::transConvertInst(SPIRVValue *BV, Function *F, CO = Instruction::BitCast; if (Src->getType()->isPointerTy() && !Dst->isPointerTy()) { if (auto *DstVecTy = dyn_cast(Dst)) { - assert(DstVecTy->getElementType()->isIntegerTy(32) && - DstVecTy->getNumElements() == 2 && - "Expected vector of two 32-bit integer components"); - auto *Int64Ty = Type::getInt64Ty(BB->getContext()); + unsigned TotalBitWidth = + DstVecTy->getElementType()->getIntegerBitWidth() * + DstVecTy->getNumElements(); + auto *IntTy = Type::getIntNTy(BB->getContext(), TotalBitWidth); if (BB) { - Src = CastInst::CreatePointerCast(Src, Int64Ty, "", BB); + Src = CastInst::CreatePointerCast(Src, IntTy, "", BB); } else { - Src = ConstantExpr::getPointerCast(dyn_cast(Src), Int64Ty); + Src = ConstantExpr::getPointerCast(dyn_cast(Src), IntTy); } } else { CO = Instruction::PtrToInt; } } else if (!Src->getType()->isPointerTy() && Dst->isPointerTy()) { if (auto *SrcVecTy = dyn_cast(Src->getType())) { - assert(SrcVecTy->getElementType()->isIntegerTy(32) && - SrcVecTy->getNumElements() == 2 && - "Expected vector of two 32-bit integer components"); - auto *Int64Ty = Type::getInt64Ty(BB->getContext()); + unsigned TotalBitWidth = + SrcVecTy->getElementType()->getIntegerBitWidth() * + SrcVecTy->getNumElements(); + auto *IntTy = Type::getIntNTy(BB->getContext(), TotalBitWidth); if (BB) { - Src = CastInst::Create(Instruction::BitCast, Src, Int64Ty, "", BB); + Src = CastInst::Create(Instruction::BitCast, Src, IntTy, "", BB); } else { - Src = ConstantExpr::getBitCast(dyn_cast(Src), Int64Ty); + Src = ConstantExpr::getBitCast(dyn_cast(Src), IntTy); } } CO = Instruction::IntToPtr;