diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -861,20 +861,6 @@ return ConstantFoldConstant(C, DL, TLI); } -/// Strip the pointer casts, but preserve the address space information. -// TODO: This probably doesn't make sense with opaque pointers. -static Constant *StripPtrCastKeepAS(Constant *Ptr) { - assert(Ptr->getType()->isPointerTy() && "Not a pointer type"); - auto *OldPtrTy = cast(Ptr->getType()); - Ptr = cast(Ptr->stripPointerCasts()); - auto *NewPtrTy = cast(Ptr->getType()); - - // Preserve the address space number of the pointer. - if (NewPtrTy->getAddressSpace() != OldPtrTy->getAddressSpace()) - Ptr = ConstantExpr::getPointerCast(Ptr, OldPtrTy); - return Ptr; -} - /// If we can symbolically evaluate the GEP constant expression, do so. Constant *SymbolicallyEvaluateGEP(const GEPOperator *GEP, ArrayRef Ops, @@ -909,7 +895,6 @@ BitWidth, DL.getIndexedOffsetInType( SrcElemTy, ArrayRef((Value *const *)Ops.data() + 1, Ops.size() - 1))); - Ptr = StripPtrCastKeepAS(Ptr); // If this is a GEP of a GEP, fold it all into a single GEP. while (auto *GEP = dyn_cast(Ptr)) { @@ -931,7 +916,6 @@ Ptr = cast(GEP->getOperand(0)); SrcElemTy = GEP->getSourceElementType(); Offset += APInt(BitWidth, DL.getIndexedOffsetInType(SrcElemTy, NestedOps)); - Ptr = StripPtrCastKeepAS(Ptr); } // If the base value for this address is a literal integer value, fold the