Skip to content

Commit 82f2ce7

Browse files
committed
[GlobalOpt] Drop bitcast handling in global to alloca fold
Pointer bitcasts no longer occur with opaque pointers -- and in this case not handling them allows us to drop the code for promoting constant expressions to instructions as well.
1 parent e277d6a commit 82f2ce7

File tree

1 file changed

+0
-71
lines changed

1 file changed

+0
-71
lines changed

llvm/lib/Transforms/IPO/GlobalOpt.cpp

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,18 +1349,6 @@ static bool isPointerValueDeadOnEntryToFunction(
13491349
SmallVector<LoadInst *, 4> Loads;
13501350
SmallVector<StoreInst *, 4> Stores;
13511351
for (auto *U : GV->users()) {
1352-
if (Operator::getOpcode(U) == Instruction::BitCast) {
1353-
for (auto *UU : U->users()) {
1354-
if (auto *LI = dyn_cast<LoadInst>(UU))
1355-
Loads.push_back(LI);
1356-
else if (auto *SI = dyn_cast<StoreInst>(UU))
1357-
Stores.push_back(SI);
1358-
else
1359-
return false;
1360-
}
1361-
continue;
1362-
}
1363-
13641352
Instruction *I = dyn_cast<Instruction>(U);
13651353
if (!I)
13661354
return false;
@@ -1410,62 +1398,6 @@ static bool isPointerValueDeadOnEntryToFunction(
14101398
return true;
14111399
}
14121400

1413-
/// C may have non-instruction users. Can all of those users be turned into
1414-
/// instructions?
1415-
static bool allNonInstructionUsersCanBeMadeInstructions(Constant *C) {
1416-
// We don't do this exhaustively. The most common pattern that we really need
1417-
// to care about is a constant GEP or constant bitcast - so just looking
1418-
// through one single ConstantExpr.
1419-
//
1420-
// The set of constants that this function returns true for must be able to be
1421-
// handled by makeAllConstantUsesInstructions.
1422-
for (auto *U : C->users()) {
1423-
if (isa<Instruction>(U))
1424-
continue;
1425-
if (!isa<ConstantExpr>(U))
1426-
// Non instruction, non-constantexpr user; cannot convert this.
1427-
return false;
1428-
for (auto *UU : U->users())
1429-
if (!isa<Instruction>(UU))
1430-
// A constantexpr used by another constant. We don't try and recurse any
1431-
// further but just bail out at this point.
1432-
return false;
1433-
}
1434-
1435-
return true;
1436-
}
1437-
1438-
/// C may have non-instruction users, and
1439-
/// allNonInstructionUsersCanBeMadeInstructions has returned true. Convert the
1440-
/// non-instruction users to instructions.
1441-
static void makeAllConstantUsesInstructions(Constant *C) {
1442-
SmallVector<ConstantExpr*,4> Users;
1443-
for (auto *U : C->users()) {
1444-
if (isa<ConstantExpr>(U))
1445-
Users.push_back(cast<ConstantExpr>(U));
1446-
else
1447-
// We should never get here; allNonInstructionUsersCanBeMadeInstructions
1448-
// should not have returned true for C.
1449-
assert(
1450-
isa<Instruction>(U) &&
1451-
"Can't transform non-constantexpr non-instruction to instruction!");
1452-
}
1453-
1454-
SmallVector<Value*,4> UUsers;
1455-
for (auto *U : Users) {
1456-
UUsers.clear();
1457-
append_range(UUsers, U->users());
1458-
for (auto *UU : UUsers) {
1459-
Instruction *UI = cast<Instruction>(UU);
1460-
Instruction *NewU = U->getAsInstruction(UI);
1461-
UI->replaceUsesOfWith(U, NewU);
1462-
}
1463-
// We've replaced all the uses, so destroy the constant. (destroyConstant
1464-
// will update value handles and metadata.)
1465-
U->destroyConstant();
1466-
}
1467-
}
1468-
14691401
// For a global variable with one store, if the store dominates any loads,
14701402
// those loads will always load the stored value (as opposed to the
14711403
// initializer), even in the presence of recursion.
@@ -1523,7 +1455,6 @@ processInternalGlobal(GlobalVariable *GV, const GlobalStatus &GS,
15231455
GV->getValueType()->isSingleValueType() &&
15241456
GV->getType()->getAddressSpace() == 0 &&
15251457
!GV->isExternallyInitialized() &&
1526-
allNonInstructionUsersCanBeMadeInstructions(GV) &&
15271458
GS.AccessingFunction->doesNotRecurse() &&
15281459
isPointerValueDeadOnEntryToFunction(GS.AccessingFunction, GV,
15291460
LookupDomTree)) {
@@ -1539,8 +1470,6 @@ processInternalGlobal(GlobalVariable *GV, const GlobalStatus &GS,
15391470
if (!isa<UndefValue>(GV->getInitializer()))
15401471
new StoreInst(GV->getInitializer(), Alloca, &FirstI);
15411472

1542-
makeAllConstantUsesInstructions(GV);
1543-
15441473
GV->replaceAllUsesWith(Alloca);
15451474
GV->eraseFromParent();
15461475
++NumLocalized;

0 commit comments

Comments
 (0)