Skip to content

Commit 5ea3531

Browse files
committed
[SROA] NFC: Extract common code to createAndCheckVectorTypesForPromotion
Change-Id: Iea5d60b12e2de7033fc1a71e80aa96c261e998bf
1 parent 8e8f9c0 commit 5ea3531

File tree

1 file changed

+31
-25
lines changed

1 file changed

+31
-25
lines changed

llvm/lib/Transforms/Scalar/SROA.cpp

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,6 +2304,34 @@ static VectorType *isVectorPromotionViable(Partition &P, const DataLayout &DL) {
23042304
}
23052305
}
23062306
};
2307+
auto createAndCheckVectorTypesForPromotion =
2308+
[&](SetVector<Type *> OtherTys,
2309+
SmallVector<VectorType *, 4> CandidateTysCopy) {
2310+
// Consider additional vector types where the element type size is a
2311+
// multiple of load/store element size.
2312+
for (Type *Ty : OtherTys) {
2313+
if (!VectorType::isValidElementType(Ty))
2314+
continue;
2315+
unsigned TypeSize = DL.getTypeSizeInBits(Ty).getFixedValue();
2316+
// Make a copy of CandidateTys and iterate through it, because we
2317+
// might append to CandidateTys in the loop.
2318+
for (VectorType *&VTy : CandidateTysCopy) {
2319+
unsigned VectorSize = DL.getTypeSizeInBits(VTy).getFixedValue();
2320+
unsigned ElementSize =
2321+
DL.getTypeSizeInBits(VTy->getElementType()).getFixedValue();
2322+
if (TypeSize != VectorSize && TypeSize != ElementSize &&
2323+
VectorSize % TypeSize == 0) {
2324+
VectorType *NewVTy =
2325+
VectorType::get(Ty, VectorSize / TypeSize, false);
2326+
CheckCandidateType(NewVTy);
2327+
}
2328+
}
2329+
}
2330+
2331+
return checkVectorTypesForPromotion(
2332+
P, DL, CandidateTys, HaveCommonEltTy, CommonEltTy, HaveVecPtrTy,
2333+
HaveCommonVecPtrTy, CommonVecPtrTy);
2334+
};
23072335

23082336
// Put load and store types into a set for de-duplication.
23092337
for (const Slice &S : P) {
@@ -2325,31 +2353,9 @@ static VectorType *isVectorPromotionViable(Partition &P, const DataLayout &DL) {
23252353
HaveCommonVecPtrTy, CommonVecPtrTy))
23262354
return VTy;
23272355

2328-
// Consider additional vector types where the element type size is a
2329-
// multiple of load/store element size.
2330-
for (Type *Ty : LoadStoreTys) {
2331-
if (!VectorType::isValidElementType(Ty))
2332-
continue;
2333-
unsigned TypeSize = DL.getTypeSizeInBits(Ty).getFixedValue();
2334-
// Make a copy of CandidateTys and iterate through it, because we might
2335-
// append to CandidateTys in the loop.
2336-
SmallVector<VectorType *, 4> CandidateTysCopy = CandidateTys;
2337-
CandidateTys.clear();
2338-
for (VectorType *&VTy : CandidateTysCopy) {
2339-
unsigned VectorSize = DL.getTypeSizeInBits(VTy).getFixedValue();
2340-
unsigned ElementSize =
2341-
DL.getTypeSizeInBits(VTy->getElementType()).getFixedValue();
2342-
if (TypeSize != VectorSize && TypeSize != ElementSize &&
2343-
VectorSize % TypeSize == 0) {
2344-
VectorType *NewVTy = VectorType::get(Ty, VectorSize / TypeSize, false);
2345-
CheckCandidateType(NewVTy);
2346-
}
2347-
}
2348-
}
2349-
2350-
return checkVectorTypesForPromotion(P, DL, CandidateTys, HaveCommonEltTy,
2351-
CommonEltTy, HaveVecPtrTy,
2352-
HaveCommonVecPtrTy, CommonVecPtrTy);
2356+
SmallVector<VectorType *, 4> CandidateTysCopy = CandidateTys;
2357+
CandidateTys.clear();
2358+
return createAndCheckVectorTypesForPromotion(LoadStoreTys, CandidateTysCopy);
23532359
}
23542360

23552361
/// Test whether a slice of an alloca is valid for integer widening.

0 commit comments

Comments
 (0)