Skip to content

Commit 4b415cb

Browse files
jcranmer-intelsvenvh
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.
1 parent 1341e54 commit 4b415cb

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

lib/SPIRV/SPIRVRegularizeLLVM.cpp

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

lib/SPIRV/SPIRVUtil.cpp

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

0 commit comments

Comments
 (0)