[PATCH] D156555: ConstantFolding: remove function in context of opaque ptrs

Ramkumar Ramachandra via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 28 09:33:39 PDT 2023


artagnon created this revision.
artagnon added reviewers: nikic, arsenm, spatel.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
artagnon requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.

The function StripPtrCastKeepAS() no longer makes any sense, as we've
migrated to using opaque pointers throughout the codebase. Hence, remove
it. No changes to tests are required.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156555

Files:
  llvm/lib/Analysis/ConstantFolding.cpp


Index: llvm/lib/Analysis/ConstantFolding.cpp
===================================================================
--- llvm/lib/Analysis/ConstantFolding.cpp
+++ 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<PointerType>(Ptr->getType());
-  Ptr = cast<Constant>(Ptr->stripPointerCasts());
-  auto *NewPtrTy = cast<PointerType>(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<Constant *> 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<GEPOperator>(Ptr)) {
@@ -931,7 +916,6 @@
     Ptr = cast<Constant>(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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156555.545198.patch
Type: text/x-patch
Size: 1701 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230728/c7e04b58/attachment.bin>


More information about the llvm-commits mailing list