[llvm] 1de568d - [GlobalOpt] Simplify replacement of call with global

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 22 00:50:14 PDT 2023


Author: Nikita Popov
Date: 2023-08-22T09:50:04+02:00
New Revision: 1de568d129bc9b884b403a41ea4ae2ca15b1c504

URL: https://github.com/llvm/llvm-project/commit/1de568d129bc9b884b403a41ea4ae2ca15b1c504
DIFF: https://github.com/llvm/llvm-project/commit/1de568d129bc9b884b403a41ea4ae2ca15b1c504.diff

LOG: [GlobalOpt] Simplify replacement of call with global

With opaque pointers, we no longer need to insert the bitcast.

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/GlobalOpt.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
index 381ced66e12be8..245ea77bd805ee 100644
--- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -930,22 +930,7 @@ OptimizeGlobalAddressOfAllocation(GlobalVariable *GV, CallInst *CI,
   }
 
   // Update users of the allocation to use the new global instead.
-  BitCastInst *TheBC = nullptr;
-  while (!CI->use_empty()) {
-    Instruction *User = cast<Instruction>(CI->user_back());
-    if (BitCastInst *BCI = dyn_cast<BitCastInst>(User)) {
-      if (BCI->getType() == NewGV->getType()) {
-        BCI->replaceAllUsesWith(NewGV);
-        BCI->eraseFromParent();
-      } else {
-        BCI->setOperand(0, NewGV);
-      }
-    } else {
-      if (!TheBC)
-        TheBC = new BitCastInst(NewGV, CI->getType(), "newgv", CI);
-      User->replaceUsesOfWith(CI, TheBC);
-    }
-  }
+  CI->replaceAllUsesWith(NewGV);
 
   SmallSetVector<Constant *, 1> RepValues;
   RepValues.insert(NewGV);


        


More information about the llvm-commits mailing list