[PATCH] D106589: [GlobalOpt] support ConstantExpr use of global address for OptimizeGlobalAddressOfMalloc

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 22 13:39:36 PDT 2021


efriedma added inline comments.


================
Comment at: llvm/lib/Transforms/IPO/GlobalOpt.cpp:737
+          return false;
+      } else if (auto *CE = dyn_cast<ConstantExpr>(U)) {
+        // Check further the ConstantExpr.
----------------
I don't think you can just look past all ConstantExprs here?  Maybe `dyn_cast<GEPOperator>(U)`?


================
Comment at: llvm/lib/Transforms/IPO/GlobalOpt.cpp:962
   // Loop over all uses of GV, processing them in turn.
-  while (!GV->use_empty()) {
-    if (StoreInst *SI = dyn_cast<StoreInst>(GV->user_back())) {
+  for (auto UI = GV->user_begin(), UE = GV->user_end(); UI != UE;) {
+    // We're likely changing the use list, so use a mutation-safe
----------------
Not sure why you're changing the pattern used here.  It's a lot easier to show the `while (!GV->use_empty()) {` loop works correctly.


================
Comment at: llvm/lib/Transforms/IPO/GlobalOpt.cpp:1063
+        if (SI->getOperand(0) == V &&
+            SI->getOperand(1)->stripPointerCasts() != GV)
+          return false; // Storing the pointer itself... bad.
----------------
`VUse.getOperandNo() == 0`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106589



More information about the llvm-commits mailing list