Skip to content

Commit

Permalink
handle more vector types
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bashbaug committed Dec 29, 2024
1 parent 145a964 commit 2a725d2
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/SPIRV/SPIRVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FixedVectorType>(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<Constant>(Src), Int64Ty);
Src = ConstantExpr::getPointerCast(dyn_cast<Constant>(Src), IntTy);
}
} else {
CO = Instruction::PtrToInt;
}
} else if (!Src->getType()->isPointerTy() && Dst->isPointerTy()) {
if (auto *SrcVecTy = dyn_cast<FixedVectorType>(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<Constant>(Src), Int64Ty);
Src = ConstantExpr::getBitCast(dyn_cast<Constant>(Src), IntTy);
}
}
CO = Instruction::IntToPtr;
Expand Down

0 comments on commit 2a725d2

Please sign in to comment.