diff options
Diffstat (limited to 'lib/Transforms/Scalar/SROA.cpp')
-rw-r--r-- | lib/Transforms/Scalar/SROA.cpp | 215 |
1 files changed, 137 insertions, 78 deletions
diff --git a/lib/Transforms/Scalar/SROA.cpp b/lib/Transforms/Scalar/SROA.cpp index eab77cf4cda9..33f90d0b01e4 100644 --- a/lib/Transforms/Scalar/SROA.cpp +++ b/lib/Transforms/Scalar/SROA.cpp @@ -1,9 +1,8 @@ //===- SROA.cpp - Scalar Replacement Of Aggregates ------------------------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// /// \file @@ -222,13 +221,6 @@ public: } // end anonymous namespace -namespace llvm { - -template <typename T> struct isPodLike; -template <> struct isPodLike<Slice> { static const bool value = true; }; - -} // end namespace llvm - /// Representation of the alloca slices. /// /// This class represents the slices of an alloca which are formed by its @@ -721,6 +713,13 @@ private: return Base::visitBitCastInst(BC); } + void visitAddrSpaceCastInst(AddrSpaceCastInst &ASC) { + if (ASC.use_empty()) + return markAsDead(ASC); + + return Base::visitAddrSpaceCastInst(ASC); + } + void visitGetElementPtrInst(GetElementPtrInst &GEPI) { if (GEPI.use_empty()) return markAsDead(GEPI); @@ -784,7 +783,10 @@ private: if (!IsOffsetKnown) return PI.setAborted(&LI); - const DataLayout &DL = LI.getModule()->getDataLayout(); + if (LI.isVolatile() && + LI.getPointerAddressSpace() != DL.getAllocaAddrSpace()) + return PI.setAborted(&LI); + uint64_t Size = DL.getTypeStoreSize(LI.getType()); return handleLoadOrStore(LI.getType(), LI, Offset, Size, LI.isVolatile()); } @@ -796,7 +798,10 @@ private: if (!IsOffsetKnown) return PI.setAborted(&SI); - const DataLayout &DL = SI.getModule()->getDataLayout(); + if (SI.isVolatile() && + SI.getPointerAddressSpace() != DL.getAllocaAddrSpace()) + return PI.setAborted(&SI); + uint64_t Size = DL.getTypeStoreSize(ValOp->getType()); // If this memory access can be shown to *statically* extend outside the @@ -831,6 +836,11 @@ private: if (!IsOffsetKnown) return PI.setAborted(&II); + // Don't replace this with a store with a different address space. TODO: + // Use a store with the casted new alloca? + if (II.isVolatile() && II.getDestAddressSpace() != DL.getAllocaAddrSpace()) + return PI.setAborted(&II); + insertUse(II, Offset, Length ? Length->getLimitedValue() : AllocSize - Offset.getLimitedValue(), (bool)Length); @@ -850,6 +860,13 @@ private: if (!IsOffsetKnown) return PI.setAborted(&II); + // Don't replace this with a load/store with a different address space. + // TODO: Use a store with the casted new alloca? + if (II.isVolatile() && + (II.getDestAddressSpace() != DL.getAllocaAddrSpace() || + II.getSourceAddressSpace() != DL.getAllocaAddrSpace())) + return PI.setAborted(&II); + // This side of the transfer is completely out-of-bounds, and so we can // nuke the entire transfer. However, we also need to nuke the other side // if already added to our partitions. @@ -957,7 +974,7 @@ private: if (!GEP->hasAllZeroIndices()) return GEP; } else if (!isa<BitCastInst>(I) && !isa<PHINode>(I) && - !isa<SelectInst>(I)) { + !isa<SelectInst>(I) && !isa<AddrSpaceCastInst>(I)) { return I; } @@ -1173,12 +1190,16 @@ static Type *findCommonType(AllocaSlices::const_iterator B, /// FIXME: This should be hoisted into a generic utility, likely in /// Transforms/Util/Local.h static bool isSafePHIToSpeculate(PHINode &PN) { + const DataLayout &DL = PN.getModule()->getDataLayout(); + // For now, we can only do this promotion if the load is in the same block // as the PHI, and if there are no stores between the phi and load. // TODO: Allow recursive phi users. // TODO: Allow stores. BasicBlock *BB = PN.getParent(); unsigned MaxAlign = 0; + uint64_t APWidth = DL.getIndexTypeSizeInBits(PN.getType()); + APInt MaxSize(APWidth, 0); bool HaveLoad = false; for (User *U : PN.users()) { LoadInst *LI = dyn_cast<LoadInst>(U); @@ -1197,15 +1218,15 @@ static bool isSafePHIToSpeculate(PHINode &PN) { if (BBI->mayWriteToMemory()) return false; + uint64_t Size = DL.getTypeStoreSizeInBits(LI->getType()); MaxAlign = std::max(MaxAlign, LI->getAlignment()); + MaxSize = MaxSize.ult(Size) ? APInt(APWidth, Size) : MaxSize; HaveLoad = true; } if (!HaveLoad) return false; - const DataLayout &DL = PN.getModule()->getDataLayout(); - // We can only transform this if it is safe to push the loads into the // predecessor blocks. The only thing to watch out for is that we can't put // a possibly trapping load in the predecessor if it is a critical edge. @@ -1227,7 +1248,7 @@ static bool isSafePHIToSpeculate(PHINode &PN) { // If this pointer is always safe to load, or if we can prove that there // is already a load in the block, then we can move the load to the pred // block. - if (isSafeToLoadUnconditionally(InVal, MaxAlign, DL, TI)) + if (isSafeToLoadUnconditionally(InVal, MaxAlign, MaxSize, DL, TI)) continue; return false; @@ -1239,15 +1260,14 @@ static bool isSafePHIToSpeculate(PHINode &PN) { static void speculatePHINodeLoads(PHINode &PN) { LLVM_DEBUG(dbgs() << " original: " << PN << "\n"); - Type *LoadTy = cast<PointerType>(PN.getType())->getElementType(); + LoadInst *SomeLoad = cast<LoadInst>(PN.user_back()); + Type *LoadTy = SomeLoad->getType(); IRBuilderTy PHIBuilder(&PN); PHINode *NewPN = PHIBuilder.CreatePHI(LoadTy, PN.getNumIncomingValues(), PN.getName() + ".sroa.speculated"); // Get the AA tags and alignment to use from one of the loads. It doesn't // matter which one we get and if any differ. - LoadInst *SomeLoad = cast<LoadInst>(PN.user_back()); - AAMDNodes AATags; SomeLoad->getAAMetadata(AATags); unsigned Align = SomeLoad->getAlignment(); @@ -1278,7 +1298,8 @@ static void speculatePHINodeLoads(PHINode &PN) { IRBuilderTy PredBuilder(TI); LoadInst *Load = PredBuilder.CreateLoad( - InVal, (PN.getName() + ".sroa.speculate.load." + Pred->getName())); + LoadTy, InVal, + (PN.getName() + ".sroa.speculate.load." + Pred->getName())); ++NumLoadsSpeculated; Load->setAlignment(Align); if (AATags) @@ -1317,9 +1338,11 @@ static bool isSafeSelectToSpeculate(SelectInst &SI) { // Both operands to the select need to be dereferenceable, either // absolutely (e.g. allocas) or at this point because we can see other // accesses to it. - if (!isSafeToLoadUnconditionally(TValue, LI->getAlignment(), DL, LI)) + if (!isSafeToLoadUnconditionally(TValue, LI->getType(), LI->getAlignment(), + DL, LI)) return false; - if (!isSafeToLoadUnconditionally(FValue, LI->getAlignment(), DL, LI)) + if (!isSafeToLoadUnconditionally(FValue, LI->getType(), LI->getAlignment(), + DL, LI)) return false; } @@ -1338,10 +1361,10 @@ static void speculateSelectInstLoads(SelectInst &SI) { assert(LI->isSimple() && "We only speculate simple loads"); IRB.SetInsertPoint(LI); - LoadInst *TL = - IRB.CreateLoad(TV, LI->getName() + ".sroa.speculate.load.true"); - LoadInst *FL = - IRB.CreateLoad(FV, LI->getName() + ".sroa.speculate.load.false"); + LoadInst *TL = IRB.CreateLoad(LI->getType(), TV, + LI->getName() + ".sroa.speculate.load.true"); + LoadInst *FL = IRB.CreateLoad(LI->getType(), FV, + LI->getName() + ".sroa.speculate.load.false"); NumLoadsSpeculated += 2; // Transfer alignment and AA info if present. @@ -1379,8 +1402,8 @@ static Value *buildGEP(IRBuilderTy &IRB, Value *BasePtr, if (Indices.size() == 1 && cast<ConstantInt>(Indices.back())->isZero()) return BasePtr; - return IRB.CreateInBoundsGEP(nullptr, BasePtr, Indices, - NamePrefix + "sroa_idx"); + return IRB.CreateInBoundsGEP(BasePtr->getType()->getPointerElementType(), + BasePtr, Indices, NamePrefix + "sroa_idx"); } /// Get a natural GEP off of the BasePtr walking through Ty toward @@ -1569,7 +1592,14 @@ static Value *getAdjustedPtr(IRBuilderTy &IRB, const DataLayout &DL, Value *Ptr, Value *Int8Ptr = nullptr; APInt Int8PtrOffset(Offset.getBitWidth(), 0); - Type *TargetTy = PointerTy->getPointerElementType(); + PointerType *TargetPtrTy = cast<PointerType>(PointerTy); + Type *TargetTy = TargetPtrTy->getElementType(); + + // As `addrspacecast` is , `Ptr` (the storage pointer) may have different + // address space from the expected `PointerTy` (the pointer to be used). + // Adjust the pointer type based the original storage pointer. + auto AS = cast<PointerType>(Ptr->getType())->getAddressSpace(); + PointerTy = TargetTy->getPointerTo(AS); do { // First fold any existing GEPs into the offset. @@ -1599,7 +1629,7 @@ static Value *getAdjustedPtr(IRBuilderTy &IRB, const DataLayout &DL, Value *Ptr, OffsetBasePtr = Ptr; // If we also found a pointer of the right type, we're done. if (P->getType() == PointerTy) - return P; + break; } // Stash this pointer if we've found an i8*. @@ -1638,8 +1668,11 @@ static Value *getAdjustedPtr(IRBuilderTy &IRB, const DataLayout &DL, Value *Ptr, Ptr = OffsetPtr; // On the off chance we were targeting i8*, guard the bitcast here. - if (Ptr->getType() != PointerTy) - Ptr = IRB.CreateBitCast(Ptr, PointerTy, NamePrefix + "sroa_cast"); + if (cast<PointerType>(Ptr->getType()) != TargetPtrTy) { + Ptr = IRB.CreatePointerBitCastOrAddrSpaceCast(Ptr, + TargetPtrTy, + NamePrefix + "sroa_cast"); + } return Ptr; } @@ -2418,14 +2451,16 @@ private: unsigned EndIndex = getIndex(NewEndOffset); assert(EndIndex > BeginIndex && "Empty vector!"); - Value *V = IRB.CreateAlignedLoad(&NewAI, NewAI.getAlignment(), "load"); + Value *V = IRB.CreateAlignedLoad(NewAI.getAllocatedType(), &NewAI, + NewAI.getAlignment(), "load"); return extractVector(IRB, V, BeginIndex, EndIndex, "vec"); } Value *rewriteIntegerLoad(LoadInst &LI) { assert(IntTy && "We cannot insert an integer to the alloca"); assert(!LI.isVolatile()); - Value *V = IRB.CreateAlignedLoad(&NewAI, NewAI.getAlignment(), "load"); + Value *V = IRB.CreateAlignedLoad(NewAI.getAllocatedType(), &NewAI, + NewAI.getAlignment(), "load"); V = convertValue(DL, IRB, V, IntTy); assert(NewBeginOffset >= NewAllocaBeginOffset && "Out of bounds offset"); uint64_t Offset = NewBeginOffset - NewAllocaBeginOffset; @@ -2469,7 +2504,8 @@ private: (canConvertValue(DL, NewAllocaTy, TargetTy) || (IsLoadPastEnd && NewAllocaTy->isIntegerTy() && TargetTy->isIntegerTy()))) { - LoadInst *NewLI = IRB.CreateAlignedLoad(&NewAI, NewAI.getAlignment(), + LoadInst *NewLI = IRB.CreateAlignedLoad(NewAI.getAllocatedType(), &NewAI, + NewAI.getAlignment(), LI.isVolatile(), LI.getName()); if (AATags) NewLI->setAAMetadata(AATags); @@ -2505,9 +2541,9 @@ private: } } else { Type *LTy = TargetTy->getPointerTo(AS); - LoadInst *NewLI = IRB.CreateAlignedLoad(getNewAllocaSlicePtr(IRB, LTy), - getSliceAlign(TargetTy), - LI.isVolatile(), LI.getName()); + LoadInst *NewLI = IRB.CreateAlignedLoad( + TargetTy, getNewAllocaSlicePtr(IRB, LTy), getSliceAlign(TargetTy), + LI.isVolatile(), LI.getName()); if (AATags) NewLI->setAAMetadata(AATags); if (LI.isVolatile()) @@ -2524,8 +2560,7 @@ private: "Only integer type loads and stores are split"); assert(SliceSize < DL.getTypeStoreSize(LI.getType()) && "Split load isn't smaller than original load"); - assert(LI.getType()->getIntegerBitWidth() == - DL.getTypeStoreSizeInBits(LI.getType()) && + assert(DL.typeSizeEqualsStoreSize(LI.getType()) && "Non-byte-multiple bit width"); // Move the insertion point just past the load so that we can refer to it. IRB.SetInsertPoint(&*std::next(BasicBlock::iterator(&LI))); @@ -2533,8 +2568,8 @@ private: // basis for the new value. This allows us to replace the uses of LI with // the computed value, and then replace the placeholder with LI, leaving // LI only used for this computation. - Value *Placeholder = - new LoadInst(UndefValue::get(LI.getType()->getPointerTo(AS))); + Value *Placeholder = new LoadInst( + LI.getType(), UndefValue::get(LI.getType()->getPointerTo(AS))); V = insertInteger(DL, IRB, Placeholder, V, NewBeginOffset - BeginOffset, "insert"); LI.replaceAllUsesWith(V); @@ -2565,7 +2600,8 @@ private: V = convertValue(DL, IRB, V, SliceTy); // Mix in the existing elements. - Value *Old = IRB.CreateAlignedLoad(&NewAI, NewAI.getAlignment(), "load"); + Value *Old = IRB.CreateAlignedLoad(NewAI.getAllocatedType(), &NewAI, + NewAI.getAlignment(), "load"); V = insertVector(IRB, Old, V, BeginIndex, "vec"); } StoreInst *Store = IRB.CreateAlignedStore(V, &NewAI, NewAI.getAlignment()); @@ -2581,8 +2617,8 @@ private: assert(IntTy && "We cannot extract an integer from the alloca"); assert(!SI.isVolatile()); if (DL.getTypeSizeInBits(V->getType()) != IntTy->getBitWidth()) { - Value *Old = - IRB.CreateAlignedLoad(&NewAI, NewAI.getAlignment(), "oldload"); + Value *Old = IRB.CreateAlignedLoad(NewAI.getAllocatedType(), &NewAI, + NewAI.getAlignment(), "oldload"); Old = convertValue(DL, IRB, Old, IntTy); assert(BeginOffset >= NewAllocaBeginOffset && "Out of bounds offset"); uint64_t Offset = BeginOffset - NewAllocaBeginOffset; @@ -2619,8 +2655,7 @@ private: assert(!SI.isVolatile()); assert(V->getType()->isIntegerTy() && "Only integer type loads and stores are split"); - assert(V->getType()->getIntegerBitWidth() == - DL.getTypeStoreSizeInBits(V->getType()) && + assert(DL.typeSizeEqualsStoreSize(V->getType()) && "Non-byte-multiple bit width"); IntegerType *NarrowTy = Type::getIntNTy(SI.getContext(), SliceSize * 8); V = extractInteger(DL, IRB, V, NarrowTy, NewBeginOffset - BeginOffset, @@ -2731,15 +2766,26 @@ private: Type *AllocaTy = NewAI.getAllocatedType(); Type *ScalarTy = AllocaTy->getScalarType(); + + const bool CanContinue = [&]() { + if (VecTy || IntTy) + return true; + if (BeginOffset > NewAllocaBeginOffset || + EndOffset < NewAllocaEndOffset) + return false; + auto *C = cast<ConstantInt>(II.getLength()); + if (C->getBitWidth() > 64) + return false; + const auto Len = C->getZExtValue(); + auto *Int8Ty = IntegerType::getInt8Ty(NewAI.getContext()); + auto *SrcTy = VectorType::get(Int8Ty, Len); + return canConvertValue(DL, SrcTy, AllocaTy) && + DL.isLegalInteger(DL.getTypeSizeInBits(ScalarTy)); + }(); // If this doesn't map cleanly onto the alloca type, and that type isn't // a single value type, just emit a memset. - if (!VecTy && !IntTy && - (BeginOffset > NewAllocaBeginOffset || EndOffset < NewAllocaEndOffset || - SliceSize != DL.getTypeStoreSize(AllocaTy) || - !AllocaTy->isSingleValueType() || - !DL.isLegalInteger(DL.getTypeSizeInBits(ScalarTy)) || - DL.getTypeSizeInBits(ScalarTy) % 8 != 0)) { + if (!CanContinue) { Type *SizeTy = II.getLength()->getType(); Constant *Size = ConstantInt::get(SizeTy, NewEndOffset - NewBeginOffset); CallInst *New = IRB.CreateMemSet( @@ -2774,8 +2820,8 @@ private: if (NumElements > 1) Splat = getVectorSplat(Splat, NumElements); - Value *Old = - IRB.CreateAlignedLoad(&NewAI, NewAI.getAlignment(), "oldload"); + Value *Old = IRB.CreateAlignedLoad(NewAI.getAllocatedType(), &NewAI, + NewAI.getAlignment(), "oldload"); V = insertVector(IRB, Old, Splat, BeginIndex, "vec"); } else if (IntTy) { // If this is a memset on an alloca where we can widen stores, insert the @@ -2787,8 +2833,8 @@ private: if (IntTy && (BeginOffset != NewAllocaBeginOffset || EndOffset != NewAllocaBeginOffset)) { - Value *Old = - IRB.CreateAlignedLoad(&NewAI, NewAI.getAlignment(), "oldload"); + Value *Old = IRB.CreateAlignedLoad(NewAI.getAllocatedType(), &NewAI, + NewAI.getAlignment(), "oldload"); Old = convertValue(DL, IRB, Old, IntTy); uint64_t Offset = NewBeginOffset - NewAllocaBeginOffset; V = insertInteger(DL, IRB, Old, V, Offset, "insert"); @@ -2948,18 +2994,18 @@ private: // Reset the other pointer type to match the register type we're going to // use, but using the address space of the original other pointer. + Type *OtherTy; if (VecTy && !IsWholeAlloca) { if (NumElements == 1) - OtherPtrTy = VecTy->getElementType(); + OtherTy = VecTy->getElementType(); else - OtherPtrTy = VectorType::get(VecTy->getElementType(), NumElements); - - OtherPtrTy = OtherPtrTy->getPointerTo(OtherAS); + OtherTy = VectorType::get(VecTy->getElementType(), NumElements); } else if (IntTy && !IsWholeAlloca) { - OtherPtrTy = SubIntTy->getPointerTo(OtherAS); + OtherTy = SubIntTy; } else { - OtherPtrTy = NewAllocaTy->getPointerTo(OtherAS); + OtherTy = NewAllocaTy; } + OtherPtrTy = OtherTy->getPointerTo(OtherAS); Value *SrcPtr = getAdjustedPtr(IRB, DL, OtherPtr, OtherOffset, OtherPtrTy, OtherPtr->getName() + "."); @@ -2973,28 +3019,30 @@ private: Value *Src; if (VecTy && !IsWholeAlloca && !IsDest) { - Src = IRB.CreateAlignedLoad(&NewAI, NewAI.getAlignment(), "load"); + Src = IRB.CreateAlignedLoad(NewAI.getAllocatedType(), &NewAI, + NewAI.getAlignment(), "load"); Src = extractVector(IRB, Src, BeginIndex, EndIndex, "vec"); } else if (IntTy && !IsWholeAlloca && !IsDest) { - Src = IRB.CreateAlignedLoad(&NewAI, NewAI.getAlignment(), "load"); + Src = IRB.CreateAlignedLoad(NewAI.getAllocatedType(), &NewAI, + NewAI.getAlignment(), "load"); Src = convertValue(DL, IRB, Src, IntTy); uint64_t Offset = NewBeginOffset - NewAllocaBeginOffset; Src = extractInteger(DL, IRB, Src, SubIntTy, Offset, "extract"); } else { - LoadInst *Load = IRB.CreateAlignedLoad(SrcPtr, SrcAlign, II.isVolatile(), - "copyload"); + LoadInst *Load = IRB.CreateAlignedLoad(OtherTy, SrcPtr, SrcAlign, + II.isVolatile(), "copyload"); if (AATags) Load->setAAMetadata(AATags); Src = Load; } if (VecTy && !IsWholeAlloca && IsDest) { - Value *Old = - IRB.CreateAlignedLoad(&NewAI, NewAI.getAlignment(), "oldload"); + Value *Old = IRB.CreateAlignedLoad(NewAI.getAllocatedType(), &NewAI, + NewAI.getAlignment(), "oldload"); Src = insertVector(IRB, Old, Src, BeginIndex, "vec"); } else if (IntTy && !IsWholeAlloca && IsDest) { - Value *Old = - IRB.CreateAlignedLoad(&NewAI, NewAI.getAlignment(), "oldload"); + Value *Old = IRB.CreateAlignedLoad(NewAI.getAllocatedType(), &NewAI, + NewAI.getAlignment(), "oldload"); Old = convertValue(DL, IRB, Old, IntTy); uint64_t Offset = NewBeginOffset - NewAllocaBeginOffset; Src = insertInteger(DL, IRB, Old, Src, Offset, "insert"); @@ -3031,7 +3079,10 @@ private: ConstantInt *Size = ConstantInt::get(cast<IntegerType>(II.getArgOperand(0)->getType()), NewEndOffset - NewBeginOffset); - Value *Ptr = getNewAllocaSlicePtr(IRB, OldPtr->getType()); + // Lifetime intrinsics always expect an i8* so directly get such a pointer + // for the new alloca slice. + Type *PointerTy = IRB.getInt8PtrTy(OldPtr->getType()->getPointerAddressSpace()); + Value *Ptr = getNewAllocaSlicePtr(IRB, PointerTy); Value *New; if (II.getIntrinsicID() == Intrinsic::lifetime_start) New = IRB.CreateLifetimeStart(Ptr, Size); @@ -3072,8 +3123,9 @@ private: continue; } - assert(isa<BitCastInst>(I) || isa<PHINode>(I) || - isa<SelectInst>(I) || isa<GetElementPtrInst>(I)); + assert(isa<BitCastInst>(I) || isa<AddrSpaceCastInst>(I) || + isa<PHINode>(I) || isa<SelectInst>(I) || + isa<GetElementPtrInst>(I)); for (User *U : I->users()) if (Visited.insert(cast<Instruction>(U)).second) Uses.push_back(cast<Instruction>(U)); @@ -3297,8 +3349,8 @@ private: assert(Ty->isSingleValueType()); // Load the single value and insert it using the indices. Value *GEP = - IRB.CreateInBoundsGEP(nullptr, Ptr, GEPIndices, Name + ".gep"); - LoadInst *Load = IRB.CreateAlignedLoad(GEP, Align, Name + ".load"); + IRB.CreateInBoundsGEP(BaseTy, Ptr, GEPIndices, Name + ".gep"); + LoadInst *Load = IRB.CreateAlignedLoad(Ty, GEP, Align, Name + ".load"); if (AATags) Load->setAAMetadata(AATags); Agg = IRB.CreateInsertValue(Agg, Load, Indices, Name + ".insert"); @@ -3342,7 +3394,7 @@ private: Value *ExtractValue = IRB.CreateExtractValue(Agg, Indices, Name + ".extract"); Value *InBoundsGEP = - IRB.CreateInBoundsGEP(nullptr, Ptr, GEPIndices, Name + ".gep"); + IRB.CreateInBoundsGEP(BaseTy, Ptr, GEPIndices, Name + ".gep"); StoreInst *Store = IRB.CreateAlignedStore(ExtractValue, InBoundsGEP, Align); if (AATags) @@ -3374,6 +3426,11 @@ private: return false; } + bool visitAddrSpaceCastInst(AddrSpaceCastInst &ASC) { + enqueueUsers(ASC); + return false; + } + bool visitGetElementPtrInst(GetElementPtrInst &GEPI) { enqueueUsers(GEPI); return false; @@ -3792,6 +3849,7 @@ bool SROA::presplitLoadsAndStores(AllocaInst &AI, AllocaSlices &AS) { auto AS = LI->getPointerAddressSpace(); auto *PartPtrTy = PartTy->getPointerTo(AS); LoadInst *PLoad = IRB.CreateAlignedLoad( + PartTy, getAdjustedPtr(IRB, DL, BasePtr, APInt(DL.getIndexSizeInBits(AS), PartOffset), PartPtrTy, BasePtr->getName() + "."), @@ -3933,6 +3991,7 @@ bool SROA::presplitLoadsAndStores(AllocaInst &AI, AllocaSlices &AS) { IRB.SetInsertPoint(LI); auto AS = LI->getPointerAddressSpace(); PLoad = IRB.CreateAlignedLoad( + PartTy, getAdjustedPtr(IRB, DL, LoadBasePtr, APInt(DL.getIndexSizeInBits(AS), PartOffset), LoadPartPtrTy, LoadBasePtr->getName() + "."), |