@@ -2257,6 +2257,41 @@ checkVectorTypesForPromotion(Partition &P, const DataLayout &DL,
2257
2257
return nullptr ;
2258
2258
}
2259
2259
2260
+ static VectorType *createAndCheckVectorTypesForPromotion (
2261
+ SetVector<Type *> &OtherTys, ArrayRef<VectorType *> CandidateTysCopy,
2262
+ function_ref<void (Type *)> CheckCandidateType, Partition &P,
2263
+ const DataLayout &DL, SmallVectorImpl<VectorType *> &CandidateTys,
2264
+ bool &HaveCommonEltTy, Type *&CommonEltTy, bool &HaveVecPtrTy,
2265
+ bool &HaveCommonVecPtrTy, VectorType *&CommonVecPtrTy) {
2266
+ [[maybe_unused]] VectorType *OriginalElt =
2267
+ CandidateTysCopy.size () ? CandidateTysCopy[0 ] : nullptr ;
2268
+ // Consider additional vector types where the element type size is a
2269
+ // multiple of load/store element size.
2270
+ for (Type *Ty : OtherTys) {
2271
+ if (!VectorType::isValidElementType (Ty))
2272
+ continue ;
2273
+ unsigned TypeSize = DL.getTypeSizeInBits (Ty).getFixedValue ();
2274
+ // Make a copy of CandidateTys and iterate through it, because we
2275
+ // might append to CandidateTys in the loop.
2276
+ for (VectorType *const VTy : CandidateTysCopy) {
2277
+ // The elements in the copy should remain invariant throughout the loop
2278
+ assert (CandidateTysCopy[0 ] == OriginalElt && " Different Element" );
2279
+ unsigned VectorSize = DL.getTypeSizeInBits (VTy).getFixedValue ();
2280
+ unsigned ElementSize =
2281
+ DL.getTypeSizeInBits (VTy->getElementType ()).getFixedValue ();
2282
+ if (TypeSize != VectorSize && TypeSize != ElementSize &&
2283
+ VectorSize % TypeSize == 0 ) {
2284
+ VectorType *NewVTy = VectorType::get (Ty, VectorSize / TypeSize, false );
2285
+ CheckCandidateType (NewVTy);
2286
+ }
2287
+ }
2288
+ }
2289
+
2290
+ return checkVectorTypesForPromotion (P, DL, CandidateTys, HaveCommonEltTy,
2291
+ CommonEltTy, HaveVecPtrTy,
2292
+ HaveCommonVecPtrTy, CommonVecPtrTy);
2293
+ }
2294
+
2260
2295
// / Test whether the given alloca partitioning and range of slices can be
2261
2296
// / promoted to a vector.
2262
2297
// /
@@ -2271,6 +2306,7 @@ static VectorType *isVectorPromotionViable(Partition &P, const DataLayout &DL) {
2271
2306
// we have different element types.
2272
2307
SmallVector<VectorType *, 4 > CandidateTys;
2273
2308
SetVector<Type *> LoadStoreTys;
2309
+ SetVector<Type *> DeferredTys;
2274
2310
Type *CommonEltTy = nullptr ;
2275
2311
VectorType *CommonVecPtrTy = nullptr ;
2276
2312
bool HaveVecPtrTy = false ;
@@ -2314,42 +2350,32 @@ static VectorType *isVectorPromotionViable(Partition &P, const DataLayout &DL) {
2314
2350
Ty = SI->getValueOperand ()->getType ();
2315
2351
else
2316
2352
continue ;
2353
+
2354
+ auto CandTy = Ty->getScalarType ();
2355
+ if (CandTy->isPointerTy () && (S.beginOffset () != P.beginOffset () ||
2356
+ S.endOffset () != P.endOffset ())) {
2357
+ DeferredTys.insert (Ty);
2358
+ continue ;
2359
+ }
2360
+
2317
2361
LoadStoreTys.insert (Ty);
2318
2362
// Consider any loads or stores that are the exact size of the slice.
2319
2363
if (S.beginOffset () == P.beginOffset () && S.endOffset () == P.endOffset ())
2320
2364
CheckCandidateType (Ty);
2321
2365
}
2322
2366
2323
- if (auto *VTy = checkVectorTypesForPromotion (
2324
- P, DL, CandidateTys, HaveCommonEltTy, CommonEltTy, HaveVecPtrTy,
2367
+ SmallVector<VectorType *, 4 > CandidateTysCopy = CandidateTys;
2368
+ if (auto *VTy = createAndCheckVectorTypesForPromotion (
2369
+ LoadStoreTys, CandidateTysCopy, CheckCandidateType, P, DL,
2370
+ CandidateTys, HaveCommonEltTy, CommonEltTy, HaveVecPtrTy,
2325
2371
HaveCommonVecPtrTy, CommonVecPtrTy))
2326
2372
return VTy;
2327
2373
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);
2374
+ CandidateTys.clear ();
2375
+ return createAndCheckVectorTypesForPromotion (
2376
+ DeferredTys, CandidateTysCopy, CheckCandidateType, P, DL, CandidateTys,
2377
+ HaveCommonEltTy, CommonEltTy, HaveVecPtrTy, HaveCommonVecPtrTy,
2378
+ CommonVecPtrTy);
2353
2379
}
2354
2380
2355
2381
// / Test whether a slice of an alloca is valid for integer widening.
0 commit comments