[PATCH] D107397: [GlobalOpt] Fix the load types when OptimizeGlobalAddressOfMalloc

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 3 13:21:02 PDT 2021


efriedma added inline comments.


================
Comment at: llvm/lib/Transforms/IPO/GlobalOpt.cpp:1000
     LoadInst *LI = cast<LoadInst>(U);
-    while (!LI->use_empty()) {
-      Use &LoadUse = *LI->use_begin();
-      ICmpInst *ICI = dyn_cast<ICmpInst>(LoadUse.getUser());
+    for (Use &LU : llvm::make_early_inc_range(LI->uses())) {
+      ICmpInst *ICI = dyn_cast<ICmpInst>(LU.getUser());
----------------
Why do you need to mess with the way you're iterating over the uses of LI?  Calling ConstantExpr::getBitCast() doesn't mess with the use-list of LI.


================
Comment at: llvm/lib/Transforms/IPO/GlobalOpt.cpp:1004
+        // Simply replace the use by the NewGV.
+        LU.set(ConstantExpr::getBitCast(NewGV, LI->getType()));
         continue;
----------------
Is RepValue dead with this change?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107397/new/

https://reviews.llvm.org/D107397



More information about the llvm-commits mailing list