From 503ef0a8e79ed26750ba1e064911e56e29c91f2f Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 6 Apr 2023 09:48:39 +0200 Subject: [PATCH] [InstCombine] Remove addrspacecast bitcast extraction fold (NFC) This is not relevant for opaque pointers, and as such no longer necessary. --- llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp | 18 ------------------ .../InstCombine/InstCombineLoadStoreAlloca.cpp | 2 +- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index e0872c8..0268db2 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -2708,23 +2708,5 @@ Instruction *InstCombinerImpl::visitBitCast(BitCastInst &CI) { } Instruction *InstCombinerImpl::visitAddrSpaceCast(AddrSpaceCastInst &CI) { - // If the destination pointer element type is not the same as the source's - // first do a bitcast to the destination type, and then the addrspacecast. - // This allows the cast to be exposed to other transforms. - Value *Src = CI.getOperand(0); - PointerType *SrcTy = cast(Src->getType()->getScalarType()); - PointerType *DestTy = cast(CI.getType()->getScalarType()); - - if (!SrcTy->hasSameElementTypeAs(DestTy)) { - Type *MidTy = - PointerType::getWithSamePointeeType(DestTy, SrcTy->getAddressSpace()); - // Handle vectors of pointers. - if (VectorType *VT = dyn_cast(CI.getType())) - MidTy = VectorType::get(MidTy, VT->getElementCount()); - - Value *NewBitCast = Builder.CreateBitCast(Src, MidTy); - return new AddrSpaceCastInst(NewBitCast, CI.getType()); - } - return commonPointerCastTransforms(CI); } diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp index d4eaf29..e9bb408 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp @@ -436,7 +436,7 @@ void PointerReplacer::replacePointer(Value *V) { #ifndef NDEBUG auto *PT = cast(Root.getType()); auto *NT = cast(V->getType()); - assert(PT != NT && PT->hasSameElementTypeAs(NT) && "Invalid usage"); + assert(PT != NT && "Invalid usage"); #endif WorkMap[&Root] = V; -- 2.7.4