[OpaquePtr][InferAddrSpace] Use PointerType::getWithSamePointeeType()
authorArthur Eubanks <aeubanks@google.com>
Fri, 9 Jul 2021 17:28:50 +0000 (10:28 -0700)
committerArthur Eubanks <aeubanks@google.com>
Fri, 9 Jul 2021 17:29:08 +0000 (10:29 -0700)
llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp

index c48a0e7..63b8425 100644 (file)
@@ -508,8 +508,8 @@ static Value *operandWithNewAddressSpaceOrCreateUndef(
     SmallVectorImpl<const Use *> *UndefUsesToFix) {
   Value *Operand = OperandUse.get();
 
-  Type *NewPtrTy =
-      Operand->getType()->getPointerElementType()->getPointerTo(NewAddrSpace);
+  Type *NewPtrTy = PointerType::getWithSamePointeeType(
+      cast<PointerType>(Operand->getType()), NewAddrSpace);
 
   if (Constant *C = dyn_cast<Constant>(Operand))
     return ConstantExpr::getAddrSpaceCast(C, NewPtrTy);
@@ -537,8 +537,8 @@ Value *InferAddressSpacesImpl::cloneInstructionWithNewAddressSpace(
     Instruction *I, unsigned NewAddrSpace,
     const ValueToValueMapTy &ValueWithNewAddrSpace,
     SmallVectorImpl<const Use *> *UndefUsesToFix) const {
-  Type *NewPtrType =
-      I->getType()->getPointerElementType()->getPointerTo(NewAddrSpace);
+  Type *NewPtrType = PointerType::getWithSamePointeeType(
+      cast<PointerType>(I->getType()), NewAddrSpace);
 
   if (I->getOpcode() == Instruction::AddrSpaceCast) {
     Value *Src = I->getOperand(0);
@@ -572,7 +572,8 @@ Value *InferAddressSpacesImpl::cloneInstructionWithNewAddressSpace(
   if (AS != UninitializedAddressSpace) {
     // For the assumed address space, insert an `addrspacecast` to make that
     // explicit.
-    auto *NewPtrTy = I->getType()->getPointerElementType()->getPointerTo(AS);
+    Type *NewPtrTy = PointerType::getWithSamePointeeType(
+        cast<PointerType>(I->getType()), AS);
     auto *NewI = new AddrSpaceCastInst(I, NewPtrTy);
     NewI->insertAfter(I);
     return NewI;
@@ -634,8 +635,8 @@ static Value *cloneConstantExprWithNewAddressSpace(
     ConstantExpr *CE, unsigned NewAddrSpace,
     const ValueToValueMapTy &ValueWithNewAddrSpace, const DataLayout *DL,
     const TargetTransformInfo *TTI) {
-  Type *TargetType =
-    CE->getType()->getPointerElementType()->getPointerTo(NewAddrSpace);
+  Type *TargetType = PointerType::getWithSamePointeeType(
+      cast<PointerType>(CE->getType()), NewAddrSpace);
 
   if (CE->getOpcode() == Instruction::AddrSpaceCast) {
     // Because CE is flat, the source address space must be specific.