Skip to content

Commit

Permalink
[SROA] NFC: Look at TypeStoreSize scalable property, rather than at t…
Browse files Browse the repository at this point in the history
…ype directly.

Some places in the code have checks for isa<ScalableVectorType> and use
that to bail out of the code. It's also possible to look directly at the
allocated type-size and check if the size is scalable. This means it's
possible to also support other scalable types that are not vectors (i.e.
TargetExtType).

This is split out from D136861.
  • Loading branch information
sdesmalen-arm committed Feb 15, 2023
1 parent 35276f1 commit 462227f
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions llvm/lib/Transforms/Scalar/SROA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,11 +956,12 @@ class AllocaSlices::SliceBuilder : public PtrUseVisitor<SliceBuilder> {
if (!IsOffsetKnown)
return PI.setAborted(&LI);

if (isa<ScalableVectorType>(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) {
Expand All @@ -970,10 +971,11 @@ class AllocaSlices::SliceBuilder : public PtrUseVisitor<SliceBuilder> {
if (!IsOffsetKnown)
return PI.setAborted(&SI);

if (isa<ScalableVectorType>(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
Expand Down Expand Up @@ -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<ScalableVectorType>(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
Expand Down Expand Up @@ -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<AllocaInst>(I)) {
if (isa<ScalableVectorType>(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);
}
}
}

Expand Down

0 comments on commit 462227f

Please sign in to comment.