Skip to content

Commit 0ec7507

Browse files
jcranmer-intelPavel V Chupin
authored andcommitted
Remove a few more getPointerElementType() calls.
The change in getScalarOrArrayConstantInt() is not actually exercised by the current test suite, and it may be impossible to exercise it given that the caller of the function relies on the parameter being a GEP of array type. However, this change should correctly deduce the type were it a correct call. The call in SPIRVRegularizeLLVM is of course unnecessary with opaque pointers: addrspacecast can never change the pointee type of a pointer type in such scenarios. Original commit: KhronosGroup/SPIRV-LLVM-Translator@4b415cb
1 parent 8885175 commit 0ec7507

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

llvm-spirv/lib/SPIRV/SPIRVRegularizeLLVM.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -633,12 +633,11 @@ bool SPIRVRegularizeLLVMBase::regularize() {
633633
// Add an additional bitcast in case address space cast also changes
634634
// pointer element type.
635635
if (auto *ASCast = dyn_cast<AddrSpaceCastInst>(&II)) {
636-
Type *DestTy = ASCast->getDestTy();
637-
Type *SrcTy = ASCast->getSrcTy();
638-
if (DestTy->getPointerElementType() !=
639-
SrcTy->getPointerElementType()) {
636+
PointerType *DestTy = cast<PointerType>(ASCast->getDestTy());
637+
PointerType *SrcTy = cast<PointerType>(ASCast->getSrcTy());
638+
if (!DestTy->hasSameElementTypeAs(SrcTy)) {
640639
PointerType *InterTy = PointerType::getWithSamePointeeType(
641-
cast<PointerType>(DestTy), SrcTy->getPointerAddressSpace());
640+
DestTy, SrcTy->getPointerAddressSpace());
642641
BitCastInst *NewBCast = new BitCastInst(
643642
ASCast->getPointerOperand(), InterTy, /*NameStr=*/"", ASCast);
644643
AddrSpaceCastInst *NewASCast =

llvm-spirv/lib/SPIRV/SPIRVUtil.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,8 +1235,12 @@ Value *getScalarOrArrayConstantInt(Instruction *Pos, Type *T, unsigned Len,
12351235
assert(Len == 1 && "Invalid length");
12361236
return ConstantInt::get(IT, V, IsSigned);
12371237
}
1238-
if (auto PT = dyn_cast<PointerType>(T)) {
1239-
auto ET = PT->getPointerElementType();
1238+
if (isa<PointerType>(T)) {
1239+
unsigned PointerSize =
1240+
Pos->getModule()->getDataLayout().getPointerTypeSizeInBits(T);
1241+
auto *ET = Type::getIntNTy(T->getContext(), PointerSize);
1242+
assert(cast<PointerType>(T)->isOpaqueOrPointeeTypeMatches(ET) &&
1243+
"Pointer-to-non-size_t arguments are not valid for this call");
12401244
auto AT = ArrayType::get(ET, Len);
12411245
std::vector<Constant *> EV(Len, ConstantInt::get(ET, V, IsSigned));
12421246
auto CA = ConstantArray::get(AT, EV);

0 commit comments

Comments
 (0)