[llvm] 061bb65 - [ConstantFold] Remove typed pointer specific folds (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 12 06:23:02 PDT 2023
Author: Nikita Popov
Date: 2023-07-12T15:20:29+02:00
New Revision: 061bb65f7463e84be359b2ded0db309c018f9121
URL: https://github.com/llvm/llvm-project/commit/061bb65f7463e84be359b2ded0db309c018f9121
DIFF: https://github.com/llvm/llvm-project/commit/061bb65f7463e84be359b2ded0db309c018f9121.diff
LOG: [ConstantFold] Remove typed pointer specific folds (NFC)
Added:
Modified:
llvm/lib/IR/ConstantFold.cpp
Removed:
################################################################################
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index fda8bc11bffaa0..20e2882837d13d 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -111,29 +111,6 @@ static Constant *FoldBitCast(Constant *V, Type *DestTy) {
if (SrcTy == DestTy)
return V; // no-op cast
- // Check to see if we are casting a pointer to an aggregate to a pointer to
- // the first element. If so, return the appropriate GEP instruction.
- if (PointerType *PTy = dyn_cast<PointerType>(V->getType()))
- if (PointerType *DPTy = dyn_cast<PointerType>(DestTy))
- if (PTy->getAddressSpace() == DPTy->getAddressSpace() &&
- !PTy->isOpaque() && !DPTy->isOpaque() &&
- PTy->getNonOpaquePointerElementType()->isSized()) {
- SmallVector<Value*, 8> IdxList;
- Value *Zero =
- Constant::getNullValue(Type::getInt32Ty(DPTy->getContext()));
- IdxList.push_back(Zero);
- Type *ElTy = PTy->getNonOpaquePointerElementType();
- while (ElTy && ElTy != DPTy->getNonOpaquePointerElementType()) {
- ElTy = GetElementPtrInst::getTypeAtIndex(ElTy, (uint64_t)0);
- IdxList.push_back(Zero);
- }
-
- if (ElTy == DPTy->getNonOpaquePointerElementType())
- // This GEP is inbounds because all indices are zero.
- return ConstantExpr::getInBoundsGetElementPtr(
- PTy->getNonOpaquePointerElementType(), V, IdxList);
- }
-
// Handle casts from one vector constant to another. We know that the src
// and dest type have the same size (otherwise its an illegal cast).
if (VectorType *DestPTy = dyn_cast<VectorType>(DestTy)) {
@@ -2033,11 +2010,6 @@ Constant *llvm::ConstantFoldGetElementPtr(Type *PointeeTy, Constant *C,
return InBounds ? PoisonValue::get(GEPTy) : UndefValue::get(GEPTy);
auto IsNoOp = [&]() {
- // For non-opaque pointers having multiple indices will change the result
- // type of the GEP.
- if (!C->getType()->getScalarType()->isOpaquePointerTy() && Idxs.size() != 1)
- return false;
-
// Avoid losing inrange information.
if (InRangeIndex)
return false;
@@ -2086,41 +2058,11 @@ Constant *llvm::ConstantFoldGetElementPtr(Type *PointeeTy, Constant *C,
}
}
- if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
+ if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C))
if (auto *GEP = dyn_cast<GEPOperator>(CE))
if (Constant *C = foldGEPOfGEP(GEP, PointeeTy, InBounds, Idxs))
return C;
- // Attempt to fold casts to the same type away. For example, folding:
- //
- // i32* getelementptr ([2 x i32]* bitcast ([3 x i32]* %X to [2 x i32]*),
- // i64 0, i64 0)
- // into:
- //
- // i32* getelementptr ([3 x i32]* %X, i64 0, i64 0)
- //
- // Don't fold if the cast is changing address spaces.
- Constant *Idx0 = cast<Constant>(Idxs[0]);
- if (CE->isCast() && Idxs.size() > 1 && Idx0->isNullValue()) {
- PointerType *SrcPtrTy =
- dyn_cast<PointerType>(CE->getOperand(0)->getType());
- PointerType *DstPtrTy = dyn_cast<PointerType>(CE->getType());
- if (SrcPtrTy && DstPtrTy && !SrcPtrTy->isOpaque() &&
- !DstPtrTy->isOpaque()) {
- ArrayType *SrcArrayTy =
- dyn_cast<ArrayType>(SrcPtrTy->getNonOpaquePointerElementType());
- ArrayType *DstArrayTy =
- dyn_cast<ArrayType>(DstPtrTy->getNonOpaquePointerElementType());
- if (SrcArrayTy && DstArrayTy
- && SrcArrayTy->getElementType() == DstArrayTy->getElementType()
- && SrcPtrTy->getAddressSpace() == DstPtrTy->getAddressSpace())
- return ConstantExpr::getGetElementPtr(SrcArrayTy,
- (Constant *)CE->getOperand(0),
- Idxs, InBounds, InRangeIndex);
- }
- }
- }
-
// Check to see if any array indices are not within the corresponding
// notional array or vector bounds. If so, try to determine if they can be
// factored out into preceding dimensions.
More information about the llvm-commits
mailing list