@@ -1210,8 +1210,7 @@ static bool isSafePHIToSpeculate(PHINode &PN) {
1210
1210
BasicBlock *BB = PN.getParent ();
1211
1211
Align MaxAlign;
1212
1212
uint64_t APWidth = DL.getIndexTypeSizeInBits (PN.getType ());
1213
- APInt MaxSize (APWidth, 0 );
1214
- bool HaveLoad = false ;
1213
+ Type *LoadType = nullptr ;
1215
1214
for (User *U : PN.users ()) {
1216
1215
LoadInst *LI = dyn_cast<LoadInst>(U);
1217
1216
if (!LI || !LI->isSimple ())
@@ -1223,21 +1222,27 @@ static bool isSafePHIToSpeculate(PHINode &PN) {
1223
1222
if (LI->getParent () != BB)
1224
1223
return false ;
1225
1224
1225
+ if (LoadType) {
1226
+ if (LoadType != LI->getType ())
1227
+ return false ;
1228
+ } else {
1229
+ LoadType = LI->getType ();
1230
+ }
1231
+
1226
1232
// Ensure that there are no instructions between the PHI and the load that
1227
1233
// could store.
1228
1234
for (BasicBlock::iterator BBI (PN); &*BBI != LI; ++BBI)
1229
1235
if (BBI->mayWriteToMemory ())
1230
1236
return false ;
1231
1237
1232
- uint64_t Size = DL.getTypeStoreSize (LI->getType ()).getFixedSize ();
1233
1238
MaxAlign = std::max (MaxAlign, LI->getAlign ());
1234
- MaxSize = MaxSize.ult (Size) ? APInt (APWidth, Size) : MaxSize;
1235
- HaveLoad = true ;
1236
1239
}
1237
1240
1238
- if (!HaveLoad )
1241
+ if (!LoadType )
1239
1242
return false ;
1240
1243
1244
+ APInt LoadSize = APInt (APWidth, DL.getTypeStoreSize (LoadType).getFixedSize ());
1245
+
1241
1246
// We can only transform this if it is safe to push the loads into the
1242
1247
// predecessor blocks. The only thing to watch out for is that we can't put
1243
1248
// a possibly trapping load in the predecessor if it is a critical edge.
@@ -1259,7 +1264,7 @@ static bool isSafePHIToSpeculate(PHINode &PN) {
1259
1264
// If this pointer is always safe to load, or if we can prove that there
1260
1265
// is already a load in the block, then we can move the load to the pred
1261
1266
// block.
1262
- if (isSafeToLoadUnconditionally (InVal, MaxAlign, MaxSize , DL, TI))
1267
+ if (isSafeToLoadUnconditionally (InVal, MaxAlign, LoadSize , DL, TI))
1263
1268
continue ;
1264
1269
1265
1270
return false ;
0 commit comments