[llvm] [ReplaceConstant] Don't create instructions for the same constant multiple times in the same basic block (PR #169141)

Shilei Tian via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 26 18:43:21 PST 2025


================
@@ -105,7 +109,14 @@ bool llvm::convertUsersOfConstantsToInstructions(ArrayRef<Constant *> Consts,
       if (auto *C = dyn_cast<Constant>(U.get())) {
         if (ExpandableUsers.contains(C)) {
           Changed = true;
-          auto NewInsts = expandUser(BI, C);
+          SmallVector<Instruction *, 4> &NewInsts =
+              ConstantToInstructionMap[std::make_pair(C, BI->getParent())];
+          // If the cached instruction is after the insertion point, we need to
+          // create a new one. We can't simply move the cached instruction
----------------
shiltian wrote:

yes

https://github.com/llvm/llvm-project/pull/169141


More information about the llvm-commits mailing list