@@ -1330,21 +1330,14 @@ static void speculatePHINodeLoads(PHINode &PN) {
1330
1330
// / %V = select i1 %cond, i32 %V1, i32 %V2
1331
1331
// /
1332
1332
// / We can do this to a select if its only uses are loads and if the operand
1333
- // / to the select can be loaded unconditionally. If found an intervening bitcast
1334
- // / with a single use of the load, allow the promotion.
1333
+ // / to the select can be loaded unconditionally.
1335
1334
static bool isSafeSelectToSpeculate (SelectInst &SI) {
1336
1335
Value *TValue = SI.getTrueValue ();
1337
1336
Value *FValue = SI.getFalseValue ();
1338
1337
const DataLayout &DL = SI.getModule ()->getDataLayout ();
1339
1338
1340
1339
for (User *U : SI.users ()) {
1341
- LoadInst *LI;
1342
- BitCastInst *BC = dyn_cast<BitCastInst>(U);
1343
- if (BC && BC->hasOneUse ())
1344
- LI = dyn_cast<LoadInst>(*BC->user_begin ());
1345
- else
1346
- LI = dyn_cast<LoadInst>(U);
1347
-
1340
+ LoadInst *LI = dyn_cast<LoadInst>(U);
1348
1341
if (!LI || !LI->isSimple ())
1349
1342
return false ;
1350
1343
@@ -1370,24 +1363,10 @@ static void speculateSelectInstLoads(SelectInst &SI) {
1370
1363
Value *FV = SI.getFalseValue ();
1371
1364
// Replace the loads of the select with a select of two loads.
1372
1365
while (!SI.use_empty ()) {
1373
- LoadInst *LI;
1374
- BitCastInst *BC = dyn_cast<BitCastInst>(SI.user_back ());
1375
- if (BC) {
1376
- assert (BC->hasOneUse () && " Bitcast should have a single use." );
1377
- LI = cast<LoadInst>(BC->user_back ());
1378
- } else {
1379
- LI = cast<LoadInst>(SI.user_back ());
1380
- }
1381
-
1366
+ LoadInst *LI = cast<LoadInst>(SI.user_back ());
1382
1367
assert (LI->isSimple () && " We only speculate simple loads" );
1383
1368
1384
1369
IRB.SetInsertPoint (LI);
1385
- if (BC) {
1386
- // Cast the operands to bitcast's target type.
1387
- TV = IRB.CreateBitCast (TV, BC->getType (), TV->getName () + " .sroa.cast" );
1388
- FV = IRB.CreateBitCast (FV, BC->getType (), FV->getName () + " .sroa.cast" );
1389
- }
1390
-
1391
1370
LoadInst *TL = IRB.CreateLoad (LI->getType (), TV,
1392
1371
LI->getName () + " .sroa.speculate.load.true" );
1393
1372
LoadInst *FL = IRB.CreateLoad (LI->getType (), FV,
@@ -1411,8 +1390,6 @@ static void speculateSelectInstLoads(SelectInst &SI) {
1411
1390
LLVM_DEBUG (dbgs () << " speculated to: " << *V << " \n " );
1412
1391
LI->replaceAllUsesWith (V);
1413
1392
LI->eraseFromParent ();
1414
- if (BC)
1415
- BC->eraseFromParent ();
1416
1393
}
1417
1394
SI.eraseFromParent ();
1418
1395
}
0 commit comments