[llvm] 61f95c6 - IR: Simplify BlockAddress replacement (#135360)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 11 08:02:33 PDT 2025
Author: Matt Arsenault
Date: 2025-04-11T17:02:28+02:00
New Revision: 61f95c6429df523dc3f04e85a5d500008c76e1fa
URL: https://github.com/llvm/llvm-project/commit/61f95c6429df523dc3f04e85a5d500008c76e1fa
DIFF: https://github.com/llvm/llvm-project/commit/61f95c6429df523dc3f04e85a5d500008c76e1fa.diff
LOG: IR: Simplify BlockAddress replacement (#135360)
Don't repeatedly replaceAllUsesWith in a loop.
Added:
Modified:
llvm/lib/IR/BasicBlock.cpp
Removed:
################################################################################
diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp
index a6d16b157c0ad..c632b1b2dc2ab 100644
--- a/llvm/lib/IR/BasicBlock.cpp
+++ b/llvm/lib/IR/BasicBlock.cpp
@@ -223,14 +223,12 @@ BasicBlock::~BasicBlock() {
// nodes. There are no other possible uses at this point.
if (hasAddressTaken()) {
assert(!use_empty() && "There should be at least one blockaddress!");
- Constant *Replacement =
- ConstantInt::get(llvm::Type::getInt32Ty(getContext()), 1);
- while (!use_empty()) {
- BlockAddress *BA = cast<BlockAddress>(user_back());
- BA->replaceAllUsesWith(ConstantExpr::getIntToPtr(Replacement,
- BA->getType()));
- BA->destroyConstant();
- }
+ BlockAddress *BA = cast<BlockAddress>(user_back());
+
+ Constant *Replacement = ConstantInt::get(Type::getInt32Ty(getContext()), 1);
+ BA->replaceAllUsesWith(
+ ConstantExpr::getIntToPtr(Replacement, BA->getType()));
+ BA->destroyConstant();
}
assert(getParent() == nullptr && "BasicBlock still linked into the program!");
More information about the llvm-commits
mailing list