Skip to content

Commit 48b9896

Browse files
arsenmvar-const
authored andcommitted
IR: Simplify BlockAddress replacement (llvm#135360)
Don't repeatedly replaceAllUsesWith in a loop.
1 parent 247f0ce commit 48b9896

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

llvm/lib/IR/BasicBlock.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,12 @@ BasicBlock::~BasicBlock() {
223223
// nodes. There are no other possible uses at this point.
224224
if (hasAddressTaken()) {
225225
assert(!use_empty() && "There should be at least one blockaddress!");
226-
Constant *Replacement =
227-
ConstantInt::get(llvm::Type::getInt32Ty(getContext()), 1);
228-
while (!use_empty()) {
229-
BlockAddress *BA = cast<BlockAddress>(user_back());
230-
BA->replaceAllUsesWith(ConstantExpr::getIntToPtr(Replacement,
231-
BA->getType()));
232-
BA->destroyConstant();
233-
}
226+
BlockAddress *BA = cast<BlockAddress>(user_back());
227+
228+
Constant *Replacement = ConstantInt::get(Type::getInt32Ty(getContext()), 1);
229+
BA->replaceAllUsesWith(
230+
ConstantExpr::getIntToPtr(Replacement, BA->getType()));
231+
BA->destroyConstant();
234232
}
235233

236234
assert(getParent() == nullptr && "BasicBlock still linked into the program!");

0 commit comments

Comments
 (0)