[llvm] 032e5d4 - [InstCombine] Remove convertBitCastToGEP() fold (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 5 07:20:24 PDT 2023
Author: Nikita Popov
Date: 2023-04-05T16:20:14+02:00
New Revision: 032e5d403e9ade45cef8d3026b5a358ae5611c05
URL: https://github.com/llvm/llvm-project/commit/032e5d403e9ade45cef8d3026b5a358ae5611c05
DIFF: https://github.com/llvm/llvm-project/commit/032e5d403e9ade45cef8d3026b5a358ae5611c05.diff
LOG: [InstCombine] Remove convertBitCastToGEP() fold (NFC)
This only applies to typed pointers, so the fold is no longer
necessary.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index f1751c6d742b..e0872c83c06f 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -2554,57 +2554,6 @@ Instruction *InstCombinerImpl::optimizeBitCastFromPhi(CastInst &CI,
return RetVal;
}
-static Instruction *convertBitCastToGEP(BitCastInst &CI, IRBuilderBase &Builder,
- const DataLayout &DL) {
- Value *Src = CI.getOperand(0);
- PointerType *SrcPTy = cast<PointerType>(Src->getType());
- PointerType *DstPTy = cast<PointerType>(CI.getType());
-
- // Bitcasts involving opaque pointers cannot be converted into a GEP.
- if (SrcPTy->isOpaque() || DstPTy->isOpaque())
- return nullptr;
-
- Type *DstElTy = DstPTy->getNonOpaquePointerElementType();
- Type *SrcElTy = SrcPTy->getNonOpaquePointerElementType();
-
- // When the type pointed to is not sized the cast cannot be
- // turned into a gep.
- if (!SrcElTy->isSized())
- return nullptr;
-
- // If the source and destination are pointers, and this cast is equivalent
- // to a getelementptr X, 0, 0, 0... turn it into the appropriate gep.
- // This can enhance SROA and other transforms that want type-safe pointers.
- unsigned NumZeros = 0;
- while (SrcElTy && SrcElTy != DstElTy) {
- SrcElTy = GetElementPtrInst::getTypeAtIndex(SrcElTy, (uint64_t)0);
- ++NumZeros;
- }
-
- // If we found a path from the src to dest, create the getelementptr now.
- if (SrcElTy == DstElTy) {
- SmallVector<Value *, 8> Idxs(NumZeros + 1, Builder.getInt32(0));
- GetElementPtrInst *GEP = GetElementPtrInst::Create(
- SrcPTy->getNonOpaquePointerElementType(), Src, Idxs);
-
- // If the source pointer is dereferenceable, then assume it points to an
- // allocated object and apply "inbounds" to the GEP.
- bool CanBeNull, CanBeFreed;
- if (Src->getPointerDereferenceableBytes(DL, CanBeNull, CanBeFreed)) {
- // In a non-default address space (not 0), a null pointer can not be
- // assumed inbounds, so ignore that case (dereferenceable_or_null).
- // The reason is that 'null' is not treated
diff erently in these address
- // spaces, and we consequently ignore the 'gep inbounds' special case
- // for 'null' which allows 'inbounds' on 'null' if the indices are
- // zeros.
- if (SrcPTy->getAddressSpace() == 0 || !CanBeNull)
- GEP->setIsInBounds();
- }
- return GEP;
- }
- return nullptr;
-}
-
Instruction *InstCombinerImpl::visitBitCast(BitCastInst &CI) {
// If the operands are integer typed then apply the integer transforms,
// otherwise just apply the common ones.
@@ -2617,10 +2566,6 @@ Instruction *InstCombinerImpl::visitBitCast(BitCastInst &CI) {
if (DestTy == Src->getType())
return replaceInstUsesWith(CI, Src);
- if (isa<PointerType>(SrcTy) && isa<PointerType>(DestTy))
- if (Instruction *I = convertBitCastToGEP(CI, Builder, DL))
- return I;
-
if (FixedVectorType *DestVTy = dyn_cast<FixedVectorType>(DestTy)) {
// Beware: messing with this target-specific oddity may cause trouble.
if (DestVTy->getNumElements() == 1 && SrcTy->isX86_MMXTy()) {
More information about the llvm-commits
mailing list