diff options
author | Nikita Popov <npopov@redhat.com> | 2023-07-12 15:20:29 +0200 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2023-07-12 15:20:29 +0200 |
commit | 061bb65f7463e84be359b2ded0db309c018f9121 (patch) | |
tree | a137c7059cd0b62fc4d6b3dd01b75f5a956313da /llvm/lib/IR/ConstantFold.cpp | |
parent | 5bf5570e60be4f0cd0fbfa965599c63966c55447 (diff) | |
download | llvm-061bb65f7463e84be359b2ded0db309c018f9121.zip llvm-061bb65f7463e84be359b2ded0db309c018f9121.tar.gz llvm-061bb65f7463e84be359b2ded0db309c018f9121.tar.bz2 |
[ConstantFold] Remove typed pointer specific folds (NFC)
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r-- | llvm/lib/IR/ConstantFold.cpp | 60 |
1 files changed, 1 insertions, 59 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index fda8bc1..20e2882 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. |