@@ -66,8 +66,8 @@ class VectorCombine {
66
66
public:
67
67
VectorCombine (Function &F, const TargetTransformInfo &TTI,
68
68
const DominatorTree &DT, AAResults &AA, AssumptionCache &AC,
69
- bool TryEarlyFoldsOnly)
70
- : F(F), Builder(F.getContext()), TTI(TTI), DT(DT), AA(AA), AC(AC),
69
+ const DataLayout *DL, bool TryEarlyFoldsOnly)
70
+ : F(F), Builder(F.getContext()), TTI(TTI), DT(DT), AA(AA), AC(AC), DL(DL),
71
71
TryEarlyFoldsOnly (TryEarlyFoldsOnly) {}
72
72
73
73
bool run ();
@@ -79,6 +79,7 @@ class VectorCombine {
79
79
const DominatorTree &DT;
80
80
AAResults &AA;
81
81
AssumptionCache ∾
82
+ const DataLayout *DL;
82
83
83
84
// / If true, only perform beneficial early IR transforms. Do not introduce new
84
85
// / vector operations.
@@ -181,23 +182,22 @@ bool VectorCombine::vectorizeLoadInsert(Instruction &I) {
181
182
// We use minimal alignment (maximum flexibility) because we only care about
182
183
// the dereferenceable region. When calculating cost and creating a new op,
183
184
// we may use a larger value based on alignment attributes.
184
- const DataLayout &DL = I.getModule ()->getDataLayout ();
185
185
Value *SrcPtr = Load->getPointerOperand ()->stripPointerCasts ();
186
186
assert (isa<PointerType>(SrcPtr->getType ()) && " Expected a pointer type" );
187
187
188
188
unsigned MinVecNumElts = MinVectorSize / ScalarSize;
189
189
auto *MinVecTy = VectorType::get (ScalarTy, MinVecNumElts, false );
190
190
unsigned OffsetEltIndex = 0 ;
191
191
Align Alignment = Load->getAlign ();
192
- if (!isSafeToLoadUnconditionally (SrcPtr, MinVecTy, Align (1 ), DL, Load, &AC,
192
+ if (!isSafeToLoadUnconditionally (SrcPtr, MinVecTy, Align (1 ), * DL, Load, &AC,
193
193
&DT)) {
194
194
// It is not safe to load directly from the pointer, but we can still peek
195
195
// through gep offsets and check if it safe to load from a base address with
196
196
// updated alignment. If it is, we can shuffle the element(s) into place
197
197
// after loading.
198
- unsigned OffsetBitWidth = DL. getIndexTypeSizeInBits (SrcPtr->getType ());
198
+ unsigned OffsetBitWidth = DL-> getIndexTypeSizeInBits (SrcPtr->getType ());
199
199
APInt Offset (OffsetBitWidth, 0 );
200
- SrcPtr = SrcPtr->stripAndAccumulateInBoundsConstantOffsets (DL, Offset);
200
+ SrcPtr = SrcPtr->stripAndAccumulateInBoundsConstantOffsets (* DL, Offset);
201
201
202
202
// We want to shuffle the result down from a high element of a vector, so
203
203
// the offset must be positive.
@@ -215,7 +215,7 @@ bool VectorCombine::vectorizeLoadInsert(Instruction &I) {
215
215
if (OffsetEltIndex >= MinVecNumElts)
216
216
return false ;
217
217
218
- if (!isSafeToLoadUnconditionally (SrcPtr, MinVecTy, Align (1 ), DL, Load, &AC,
218
+ if (!isSafeToLoadUnconditionally (SrcPtr, MinVecTy, Align (1 ), * DL, Load, &AC,
219
219
&DT))
220
220
return false ;
221
221
@@ -227,7 +227,7 @@ bool VectorCombine::vectorizeLoadInsert(Instruction &I) {
227
227
228
228
// Original pattern: insertelt undef, load [free casts of] PtrOp, 0
229
229
// Use the greater of the alignment on the load or its source pointer.
230
- Alignment = std::max (SrcPtr->getPointerAlignment (DL), Alignment);
230
+ Alignment = std::max (SrcPtr->getPointerAlignment (* DL), Alignment);
231
231
Type *LoadTy = Load->getType ();
232
232
unsigned AS = Load->getPointerAddressSpace ();
233
233
InstructionCost OldCost =
@@ -298,14 +298,13 @@ bool VectorCombine::widenSubvectorLoad(Instruction &I) {
298
298
// the dereferenceable region. When calculating cost and creating a new op,
299
299
// we may use a larger value based on alignment attributes.
300
300
auto *Ty = cast<FixedVectorType>(I.getType ());
301
- const DataLayout &DL = I.getModule ()->getDataLayout ();
302
301
Value *SrcPtr = Load->getPointerOperand ()->stripPointerCasts ();
303
302
assert (isa<PointerType>(SrcPtr->getType ()) && " Expected a pointer type" );
304
303
Align Alignment = Load->getAlign ();
305
- if (!isSafeToLoadUnconditionally (SrcPtr, Ty, Align (1 ), DL, Load, &AC, &DT))
304
+ if (!isSafeToLoadUnconditionally (SrcPtr, Ty, Align (1 ), * DL, Load, &AC, &DT))
306
305
return false ;
307
306
308
- Alignment = std::max (SrcPtr->getPointerAlignment (DL), Alignment);
307
+ Alignment = std::max (SrcPtr->getPointerAlignment (* DL), Alignment);
309
308
Type *LoadTy = Load->getType ();
310
309
unsigned AS = Load->getPointerAddressSpace ();
311
310
@@ -854,7 +853,6 @@ bool VectorCombine::scalarizeVPIntrinsic(Instruction &I) {
854
853
// Scalarize the intrinsic
855
854
ElementCount EC = cast<VectorType>(Op0->getType ())->getElementCount ();
856
855
Value *EVL = VPI.getArgOperand (3 );
857
- const DataLayout &DL = VPI.getModule ()->getDataLayout ();
858
856
859
857
// If the VP op might introduce UB or poison, we can scalarize it provided
860
858
// that we know the EVL > 0: If the EVL is zero, then the original VP op
@@ -867,7 +865,7 @@ bool VectorCombine::scalarizeVPIntrinsic(Instruction &I) {
867
865
else
868
866
SafeToSpeculate = isSafeToSpeculativelyExecuteWithOpcode (
869
867
*FunctionalOpcode, &VPI, nullptr , &AC, &DT);
870
- if (!SafeToSpeculate && !isKnownNonZero (EVL, DL, 0 , &AC, &VPI, &DT))
868
+ if (!SafeToSpeculate && !isKnownNonZero (EVL, * DL, 0 , &AC, &VPI, &DT))
871
869
return false ;
872
870
873
871
Value *ScalarVal =
@@ -1246,12 +1244,11 @@ bool VectorCombine::foldSingleElementStore(Instruction &I) {
1246
1244
1247
1245
if (auto *Load = dyn_cast<LoadInst>(Source)) {
1248
1246
auto VecTy = cast<VectorType>(SI->getValueOperand ()->getType ());
1249
- const DataLayout &DL = I.getModule ()->getDataLayout ();
1250
1247
Value *SrcAddr = Load->getPointerOperand ()->stripPointerCasts ();
1251
1248
// Don't optimize for atomic/volatile load or store. Ensure memory is not
1252
1249
// modified between, vector type matches store size, and index is inbounds.
1253
1250
if (!Load->isSimple () || Load->getParent () != SI->getParent () ||
1254
- !DL. typeSizeEqualsStoreSize (Load->getType ()->getScalarType ()) ||
1251
+ !DL-> typeSizeEqualsStoreSize (Load->getType ()->getScalarType ()) ||
1255
1252
SrcAddr != SI->getPointerOperand ()->stripPointerCasts ())
1256
1253
return false ;
1257
1254
@@ -1270,7 +1267,7 @@ bool VectorCombine::foldSingleElementStore(Instruction &I) {
1270
1267
NSI->copyMetadata (*SI);
1271
1268
Align ScalarOpAlignment = computeAlignmentAfterScalarization (
1272
1269
std::max (SI->getAlign (), Load->getAlign ()), NewElement->getType (), Idx,
1273
- DL);
1270
+ * DL);
1274
1271
NSI->setAlignment (ScalarOpAlignment);
1275
1272
replaceValue (I, *NSI);
1276
1273
eraseInstruction (I);
@@ -1288,8 +1285,7 @@ bool VectorCombine::scalarizeLoadExtract(Instruction &I) {
1288
1285
1289
1286
auto *VecTy = cast<VectorType>(I.getType ());
1290
1287
auto *LI = cast<LoadInst>(&I);
1291
- const DataLayout &DL = I.getModule ()->getDataLayout ();
1292
- if (LI->isVolatile () || !DL.typeSizeEqualsStoreSize (VecTy->getScalarType ()))
1288
+ if (LI->isVolatile () || !DL->typeSizeEqualsStoreSize (VecTy->getScalarType ()))
1293
1289
return false ;
1294
1290
1295
1291
InstructionCost OriginalCost =
@@ -1367,7 +1363,7 @@ bool VectorCombine::scalarizeLoadExtract(Instruction &I) {
1367
1363
VecTy->getElementType (), GEP, EI->getName () + " .scalar" ));
1368
1364
1369
1365
Align ScalarOpAlignment = computeAlignmentAfterScalarization (
1370
- LI->getAlign (), VecTy->getElementType (), Idx, DL);
1366
+ LI->getAlign (), VecTy->getElementType (), Idx, * DL);
1371
1367
NewLoad->setAlignment (ScalarOpAlignment);
1372
1368
1373
1369
replaceValue (*EI, *NewLoad);
@@ -2042,7 +2038,8 @@ PreservedAnalyses VectorCombinePass::run(Function &F,
2042
2038
TargetTransformInfo &TTI = FAM.getResult <TargetIRAnalysis>(F);
2043
2039
DominatorTree &DT = FAM.getResult <DominatorTreeAnalysis>(F);
2044
2040
AAResults &AA = FAM.getResult <AAManager>(F);
2045
- VectorCombine Combiner (F, TTI, DT, AA, AC, TryEarlyFoldsOnly);
2041
+ const DataLayout *DL = &F.getParent ()->getDataLayout ();
2042
+ VectorCombine Combiner (F, TTI, DT, AA, AC, DL, TryEarlyFoldsOnly);
2046
2043
if (!Combiner.run ())
2047
2044
return PreservedAnalyses::all ();
2048
2045
PreservedAnalyses PA;
0 commit comments