diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp index 8b2f3af2c155cc..0dc89919cf3b83 100644 --- a/llvm/lib/Transforms/Scalar/SROA.cpp +++ b/llvm/lib/Transforms/Scalar/SROA.cpp @@ -956,11 +956,12 @@ class AllocaSlices::SliceBuilder : public PtrUseVisitor { if (!IsOffsetKnown) return PI.setAborted(&LI); - if (isa(LI.getType())) + TypeSize Size = DL.getTypeStoreSize(LI.getType()); + if (Size.isScalable()) return PI.setAborted(&LI); - uint64_t Size = DL.getTypeStoreSize(LI.getType()).getFixedValue(); - return handleLoadOrStore(LI.getType(), LI, Offset, Size, LI.isVolatile()); + return handleLoadOrStore(LI.getType(), LI, Offset, Size.getFixedValue(), + LI.isVolatile()); } void visitStoreInst(StoreInst &SI) { @@ -970,10 +971,11 @@ class AllocaSlices::SliceBuilder : public PtrUseVisitor { if (!IsOffsetKnown) return PI.setAborted(&SI); - if (isa(ValOp->getType())) + TypeSize StoreSize = DL.getTypeStoreSize(ValOp->getType()); + if (StoreSize.isScalable()) return PI.setAborted(&SI); - uint64_t Size = DL.getTypeStoreSize(ValOp->getType()).getFixedValue(); + uint64_t Size = StoreSize.getFixedValue(); // If this memory access can be shown to *statically* extend outside the // bounds of the allocation, it's behavior is undefined, so simply @@ -4864,8 +4866,9 @@ SROAPass::runOnAlloca(AllocaInst &AI) { // Skip alloca forms that this analysis can't handle. auto *AT = AI.getAllocatedType(); - if (AI.isArrayAllocation() || !AT->isSized() || isa(AT) || - DL.getTypeAllocSize(AT).getFixedValue() == 0) + TypeSize Size = DL.getTypeAllocSize(AT); + if (AI.isArrayAllocation() || !AT->isSized() || Size.isScalable() || + Size.getFixedValue() == 0) return {Changed, CFGChanged}; // First, split any FCA loads and stores touching this alloca to promote @@ -4993,16 +4996,16 @@ PreservedAnalyses SROAPass::runImpl(Function &F, DomTreeUpdater &RunDTU, DTU = &RunDTU; AC = &RunAC; + const DataLayout &DL = F.getParent()->getDataLayout(); BasicBlock &EntryBB = F.getEntryBlock(); for (BasicBlock::iterator I = EntryBB.begin(), E = std::prev(EntryBB.end()); I != E; ++I) { if (AllocaInst *AI = dyn_cast(I)) { - if (isa(AI->getAllocatedType())) { - if (isAllocaPromotable(AI)) - PromotableAllocas.push_back(AI); - } else { + if (DL.getTypeAllocSize(AI->getAllocatedType()).isScalable() && + isAllocaPromotable(AI)) + PromotableAllocas.push_back(AI); + else Worklist.insert(AI); - } } }