@@ -2134,6 +2134,94 @@ static bool checkVectorTypeForPromotion(Partition &P, VectorType *VTy,
2134
2134
return true ;
2135
2135
}
2136
2136
2137
+ static VectorType *
2138
+ testVectorTyForPromotion (Partition &P, const DataLayout &DL,
2139
+ SmallVectorImpl<VectorType *> &CandidateTys,
2140
+ bool HaveCommonEltTy, Type *CommonEltTy,
2141
+ bool HaveVecPtrTy, bool HaveCommonVecPtrTy,
2142
+ VectorType *CommonVecPtrTy) {
2143
+ // If we didn't find a vector type, nothing to do here.
2144
+ if (CandidateTys.empty ())
2145
+ return nullptr ;
2146
+
2147
+ // Pointer-ness is sticky, if we had a vector-of-pointers candidate type,
2148
+ // then we should choose it, not some other alternative.
2149
+ // But, we can't perform a no-op pointer address space change via bitcast,
2150
+ // so if we didn't have a common pointer element type, bail.
2151
+ if (HaveVecPtrTy && !HaveCommonVecPtrTy)
2152
+ return nullptr ;
2153
+
2154
+ // Try to pick the "best" element type out of the choices.
2155
+ if (!HaveCommonEltTy && HaveVecPtrTy) {
2156
+ // If there was a pointer element type, there's really only one choice.
2157
+ CandidateTys.clear ();
2158
+ CandidateTys.push_back (CommonVecPtrTy);
2159
+ } else if (!HaveCommonEltTy && !HaveVecPtrTy) {
2160
+ // Integer-ify vector types.
2161
+ for (VectorType *&VTy : CandidateTys) {
2162
+ if (!VTy->getElementType ()->isIntegerTy ())
2163
+ VTy = cast<VectorType>(VTy->getWithNewType (IntegerType::getIntNTy (
2164
+ VTy->getContext (), VTy->getScalarSizeInBits ())));
2165
+ }
2166
+
2167
+ // Rank the remaining candidate vector types. This is easy because we know
2168
+ // they're all integer vectors. We sort by ascending number of elements.
2169
+ auto RankVectorTypesComp = [&DL](VectorType *RHSTy, VectorType *LHSTy) {
2170
+ (void )DL;
2171
+ assert (DL.getTypeSizeInBits (RHSTy).getFixedValue () ==
2172
+ DL.getTypeSizeInBits (LHSTy).getFixedValue () &&
2173
+ " Cannot have vector types of different sizes!" );
2174
+ assert (RHSTy->getElementType ()->isIntegerTy () &&
2175
+ " All non-integer types eliminated!" );
2176
+ assert (LHSTy->getElementType ()->isIntegerTy () &&
2177
+ " All non-integer types eliminated!" );
2178
+ return cast<FixedVectorType>(RHSTy)->getNumElements () <
2179
+ cast<FixedVectorType>(LHSTy)->getNumElements ();
2180
+ };
2181
+ auto RankVectorTypesEq = [&DL](VectorType *RHSTy, VectorType *LHSTy) {
2182
+ (void )DL;
2183
+ assert (DL.getTypeSizeInBits (RHSTy).getFixedValue () ==
2184
+ DL.getTypeSizeInBits (LHSTy).getFixedValue () &&
2185
+ " Cannot have vector types of different sizes!" );
2186
+ assert (RHSTy->getElementType ()->isIntegerTy () &&
2187
+ " All non-integer types eliminated!" );
2188
+ assert (LHSTy->getElementType ()->isIntegerTy () &&
2189
+ " All non-integer types eliminated!" );
2190
+ return cast<FixedVectorType>(RHSTy)->getNumElements () ==
2191
+ cast<FixedVectorType>(LHSTy)->getNumElements ();
2192
+ };
2193
+ llvm::sort (CandidateTys, RankVectorTypesComp);
2194
+ CandidateTys.erase (std::unique (CandidateTys.begin (), CandidateTys.end (),
2195
+ RankVectorTypesEq),
2196
+ CandidateTys.end ());
2197
+ } else {
2198
+ // The only way to have the same element type in every vector type is to
2199
+ // have the same vector type. Check that and remove all but one.
2200
+ #ifndef NDEBUG
2201
+ for (VectorType *VTy : CandidateTys) {
2202
+ assert (VTy->getElementType () == CommonEltTy &&
2203
+ " Unaccounted for element type!" );
2204
+ assert (VTy == CandidateTys[0 ] &&
2205
+ " Different vector types with the same element type!" );
2206
+ }
2207
+ #endif
2208
+ CandidateTys.resize (1 );
2209
+ }
2210
+
2211
+ // FIXME: hack. Do we have a named constant for this?
2212
+ // SDAG SDNode can't have more than 65535 operands.
2213
+ llvm::erase_if (CandidateTys, [](VectorType *VTy) {
2214
+ return cast<FixedVectorType>(VTy)->getNumElements () >
2215
+ std::numeric_limits<unsigned short >::max ();
2216
+ });
2217
+
2218
+ for (VectorType *VTy : CandidateTys)
2219
+ if (checkVectorTypeForPromotion (P, VTy, DL))
2220
+ return VTy;
2221
+
2222
+ return nullptr ;
2223
+ }
2224
+
2137
2225
// / Test whether the given alloca partitioning and range of slices can be
2138
2226
// / promoted to a vector.
2139
2227
// /
@@ -2195,6 +2283,12 @@ static VectorType *isVectorPromotionViable(Partition &P, const DataLayout &DL) {
2195
2283
if (S.beginOffset () == P.beginOffset () && S.endOffset () == P.endOffset ())
2196
2284
CheckCandidateType (Ty);
2197
2285
}
2286
+
2287
+ if (auto *VTy = testVectorTyForPromotion (
2288
+ P, DL, CandidateTys, HaveCommonEltTy, CommonEltTy, HaveVecPtrTy,
2289
+ HaveCommonVecPtrTy, CommonVecPtrTy))
2290
+ return VTy;
2291
+
2198
2292
// Consider additional vector types where the element type size is a
2199
2293
// multiple of load/store element size.
2200
2294
for (Type *Ty : LoadStoreTys) {
@@ -2204,6 +2298,7 @@ static VectorType *isVectorPromotionViable(Partition &P, const DataLayout &DL) {
2204
2298
// Make a copy of CandidateTys and iterate through it, because we might
2205
2299
// append to CandidateTys in the loop.
2206
2300
SmallVector<VectorType *, 4 > CandidateTysCopy = CandidateTys;
2301
+ CandidateTys.clear ();
2207
2302
for (VectorType *&VTy : CandidateTysCopy) {
2208
2303
unsigned VectorSize = DL.getTypeSizeInBits (VTy).getFixedValue ();
2209
2304
unsigned ElementSize =
@@ -2216,86 +2311,9 @@ static VectorType *isVectorPromotionViable(Partition &P, const DataLayout &DL) {
2216
2311
}
2217
2312
}
2218
2313
2219
- // If we didn't find a vector type, nothing to do here.
2220
- if (CandidateTys.empty ())
2221
- return nullptr ;
2222
-
2223
- // Pointer-ness is sticky, if we had a vector-of-pointers candidate type,
2224
- // then we should choose it, not some other alternative.
2225
- // But, we can't perform a no-op pointer address space change via bitcast,
2226
- // so if we didn't have a common pointer element type, bail.
2227
- if (HaveVecPtrTy && !HaveCommonVecPtrTy)
2228
- return nullptr ;
2229
-
2230
- // Try to pick the "best" element type out of the choices.
2231
- if (!HaveCommonEltTy && HaveVecPtrTy) {
2232
- // If there was a pointer element type, there's really only one choice.
2233
- CandidateTys.clear ();
2234
- CandidateTys.push_back (CommonVecPtrTy);
2235
- } else if (!HaveCommonEltTy && !HaveVecPtrTy) {
2236
- // Integer-ify vector types.
2237
- for (VectorType *&VTy : CandidateTys) {
2238
- if (!VTy->getElementType ()->isIntegerTy ())
2239
- VTy = cast<VectorType>(VTy->getWithNewType (IntegerType::getIntNTy (
2240
- VTy->getContext (), VTy->getScalarSizeInBits ())));
2241
- }
2242
-
2243
- // Rank the remaining candidate vector types. This is easy because we know
2244
- // they're all integer vectors. We sort by ascending number of elements.
2245
- auto RankVectorTypesComp = [&DL](VectorType *RHSTy, VectorType *LHSTy) {
2246
- (void )DL;
2247
- assert (DL.getTypeSizeInBits (RHSTy).getFixedValue () ==
2248
- DL.getTypeSizeInBits (LHSTy).getFixedValue () &&
2249
- " Cannot have vector types of different sizes!" );
2250
- assert (RHSTy->getElementType ()->isIntegerTy () &&
2251
- " All non-integer types eliminated!" );
2252
- assert (LHSTy->getElementType ()->isIntegerTy () &&
2253
- " All non-integer types eliminated!" );
2254
- return cast<FixedVectorType>(RHSTy)->getNumElements () <
2255
- cast<FixedVectorType>(LHSTy)->getNumElements ();
2256
- };
2257
- auto RankVectorTypesEq = [&DL](VectorType *RHSTy, VectorType *LHSTy) {
2258
- (void )DL;
2259
- assert (DL.getTypeSizeInBits (RHSTy).getFixedValue () ==
2260
- DL.getTypeSizeInBits (LHSTy).getFixedValue () &&
2261
- " Cannot have vector types of different sizes!" );
2262
- assert (RHSTy->getElementType ()->isIntegerTy () &&
2263
- " All non-integer types eliminated!" );
2264
- assert (LHSTy->getElementType ()->isIntegerTy () &&
2265
- " All non-integer types eliminated!" );
2266
- return cast<FixedVectorType>(RHSTy)->getNumElements () ==
2267
- cast<FixedVectorType>(LHSTy)->getNumElements ();
2268
- };
2269
- llvm::sort (CandidateTys, RankVectorTypesComp);
2270
- CandidateTys.erase (std::unique (CandidateTys.begin (), CandidateTys.end (),
2271
- RankVectorTypesEq),
2272
- CandidateTys.end ());
2273
- } else {
2274
- // The only way to have the same element type in every vector type is to
2275
- // have the same vector type. Check that and remove all but one.
2276
- #ifndef NDEBUG
2277
- for (VectorType *VTy : CandidateTys) {
2278
- assert (VTy->getElementType () == CommonEltTy &&
2279
- " Unaccounted for element type!" );
2280
- assert (VTy == CandidateTys[0 ] &&
2281
- " Different vector types with the same element type!" );
2282
- }
2283
- #endif
2284
- CandidateTys.resize (1 );
2285
- }
2286
-
2287
- // FIXME: hack. Do we have a named constant for this?
2288
- // SDAG SDNode can't have more than 65535 operands.
2289
- llvm::erase_if (CandidateTys, [](VectorType *VTy) {
2290
- return cast<FixedVectorType>(VTy)->getNumElements () >
2291
- std::numeric_limits<unsigned short >::max ();
2292
- });
2293
-
2294
- for (VectorType *VTy : CandidateTys)
2295
- if (checkVectorTypeForPromotion (P, VTy, DL))
2296
- return VTy;
2297
-
2298
- return nullptr ;
2314
+ return testVectorTyForPromotion (P, DL, CandidateTys, HaveCommonEltTy,
2315
+ CommonEltTy, HaveVecPtrTy, HaveCommonVecPtrTy,
2316
+ CommonVecPtrTy);
2299
2317
}
2300
2318
2301
2319
// / Test whether a slice of an alloca is valid for integer widening.
0 commit comments