Skip to content

Commit 61f95c6

Browse files
authored
IR: Simplify BlockAddress replacement (llvm#135360)
Don't repeatedly replaceAllUsesWith in a loop.
1 parent c3795ba commit 61f95c6

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)