Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle OpBitcast between pointers and non-pointers #2948

Merged
merged 6 commits into from
Jan 7, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
bashbaug committed Dec 29, 2024

Verified

This commit was signed with the committer’s verified signature.
fiji-flo Florian Dieminger
commit 2a725d2faa29bc3485be785bb56ec144de3fe2e1
24 changes: 12 additions & 12 deletions lib/SPIRV/SPIRVReader.cpp
Original file line number Diff line number Diff line change
@@ -1089,28 +1089,28 @@ Value *SPIRVToLLVM::transConvertInst(SPIRVValue *BV, Function *F,
CO = Instruction::BitCast;
bashbaug marked this conversation as resolved.
Show resolved Hide resolved
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;