[llvm] [SPIR-V] Scalarize vector of pointers for ptrtoint/inttoptr (PR #184817)
Dmitry Sidorov via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 5 09:59:38 PST 2026
================
@@ -2106,6 +2115,58 @@ SPIRVEmitIntrinsics::visitExtractElementInst(ExtractElementInst &I) {
return NewI;
}
+Instruction *SPIRVEmitIntrinsics::visitPtrToIntInst(PtrToIntInst &I) {
+ // Scalarize ptrtoint on vectors of pointers, since SPIR-V does not support
+ // vectors of pointers.
+ Type *SrcTy = I.getOperand(0)->getType();
+ auto *VecTy = dyn_cast<FixedVectorType>(SrcTy);
+
+ if (!VecTy || !VecTy->getElementType()->isPointerTy())
+ return &I;
+
+ IRBuilder<> B(I.getParent());
+ B.SetInsertPoint(&I);
+
+ unsigned NumElems = VecTy->getNumElements();
+ Type *ElemIntTy = cast<VectorType>(I.getType())->getElementType();
+ Value *Result = PoisonValue::get(I.getType());
+
+ for (unsigned Idx = 0; Idx < NumElems; ++Idx) {
----------------
MrSidims wrote:
Would it makes sense to move unrolling logic into a new utility function, that could be reused to lower not only ptrtoint/inttoptr instructions but also others, that may be operating over a vector of pointers? Like it's being done https://github.com/llvm/llvm-project/blob/main/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp#L13700
https://github.com/llvm/llvm-project/pull/184817
More information about the llvm-commits
mailing list