Skip to content

Commit 2166e8a

Browse files
committed
cleanup
1 parent 26b15b7 commit 2166e8a

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

llvm/lib/Transforms/Scalar/SROA.cpp

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,12 +2290,31 @@ checkVectorTypesForPromotion(Partition &P, const DataLayout &DL,
22902290
return cast<FixedVectorType>(VTy)->getNumElements() >
22912291
std::numeric_limits<unsigned short>::max();
22922292
});
2293+
2294+
// Find a vector type viable for promotion by iterating over all slices.
2295+
auto *VTy = llvm::find_if(CandidateTys, [&](VectorType *VTy) -> bool {
2296+
uint64_t ElementSize =
2297+
DL.getTypeSizeInBits(VTy->getElementType()).getFixedValue();
2298+
2299+
// While the definition of LLVM vectors is bitpacked, we don't support sizes
2300+
// that aren't byte sized.
2301+
if (ElementSize % 8)
2302+
return false;
2303+
assert((DL.getTypeSizeInBits(VTy).getFixedValue() % 8) == 0 &&
2304+
"vector size not a multiple of element size?");
2305+
ElementSize /= 8;
22932306

2294-
for (VectorType *VTy : CandidateTys)
2295-
if (checkVectorTypeForPromotion(P, VTy, DL, VScale))
2296-
return VTy;
2307+
for (const Slice &S : P)
2308+
if (!isVectorPromotionViableForSlice(P, S, VTy, ElementSize, DL, VScale))
2309+
return false;
22972310

2298-
return nullptr;
2311+
for (const Slice *S : P.splitSliceTails())
2312+
if (!isVectorPromotionViableForSlice(P, *S, VTy, ElementSize, DL, VScale))
2313+
return false;
2314+
2315+
return true;
2316+
});
2317+
return VTy != CandidateTys.end() ? *VTy : nullptr;
22992318
}
23002319

23012320
static VectorType *createAndCheckVectorTypesForPromotion(
@@ -5213,7 +5232,6 @@ AllocaInst *SROA::rewritePartition(AllocaInst &AI, AllocaSlices &AS,
52135232
// won't always succeed, in which case we fall back to a legal integer type
52145233
// or an i8 array of an appropriate size.
52155234
Type *SliceTy = nullptr;
5216-
VectorType *SliceVecTy = nullptr;
52175235
const DataLayout &DL = AI.getDataLayout();
52185236
unsigned VScale = AI.getFunction()->getVScaleValue();
52195237

@@ -5222,10 +5240,8 @@ AllocaInst *SROA::rewritePartition(AllocaInst &AI, AllocaSlices &AS,
52225240
// Do all uses operate on the same type?
52235241
if (CommonUseTy.first) {
52245242
TypeSize CommonUseSize = DL.getTypeAllocSize(CommonUseTy.first);
5225-
if (CommonUseSize.isFixed() && CommonUseSize.getFixedValue() >= P.size()) {
5243+
if (CommonUseSize.isFixed() && CommonUseSize.getFixedValue() >= P.size())
52265244
SliceTy = CommonUseTy.first;
5227-
SliceVecTy = dyn_cast<VectorType>(SliceTy);
5228-
}
52295245
}
52305246
// If not, can we find an appropriate subtype in the original allocated type?
52315247
if (!SliceTy)
@@ -5235,27 +5251,14 @@ AllocaInst *SROA::rewritePartition(AllocaInst &AI, AllocaSlices &AS,
52355251

52365252
// If still not, can we use the largest bitwidth integer type used?
52375253
if (!SliceTy && CommonUseTy.second)
5238-
if (DL.getTypeAllocSize(CommonUseTy.second).getFixedValue() >= P.size()) {
5254+
if (DL.getTypeAllocSize(CommonUseTy.second).getFixedValue() >= P.size())
52395255
SliceTy = CommonUseTy.second;
5240-
SliceVecTy = dyn_cast<VectorType>(SliceTy);
5241-
}
52425256
if ((!SliceTy || (SliceTy->isArrayTy() &&
52435257
SliceTy->getArrayElementType()->isIntegerTy())) &&
52445258
DL.isLegalInteger(P.size() * 8)) {
52455259
SliceTy = Type::getIntNTy(*C, P.size() * 8);
52465260
}
52475261

5248-
// If the common use types are not viable for promotion then attempt to find
5249-
// another type that is viable.
5250-
if (SliceVecTy && !checkVectorTypeForPromotion(P, SliceVecTy, DL, VScale))
5251-
if (Type *TypePartitionTy = getTypePartition(DL, AI.getAllocatedType(),
5252-
P.beginOffset(), P.size())) {
5253-
VectorType *TypePartitionVecTy = dyn_cast<VectorType>(TypePartitionTy);
5254-
if (TypePartitionVecTy &&
5255-
checkVectorTypeForPromotion(P, TypePartitionVecTy, DL, VScale))
5256-
SliceTy = TypePartitionTy;
5257-
}
5258-
52595262
if (!SliceTy)
52605263
SliceTy = ArrayType::get(Type::getInt8Ty(*C), P.size());
52615264
assert(DL.getTypeAllocSize(SliceTy).getFixedValue() >= P.size());

0 commit comments

Comments
 (0)