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

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 23 17:15:23 PDT 2021


efriedma added inline comments.


================
Comment at: llvm/lib/Transforms/IPO/GlobalOpt.cpp:738
+      } else if (auto *CE = dyn_cast<ConstantExpr>(U)) {
+        if (CE->stripPointerCasts() != P)
+          return false;
----------------
I'm not sure constant folding ensures that `CE->stripPointerCasts()` looks through exactly one pointer cast?


================
Comment at: llvm/lib/Transforms/IPO/GlobalOpt.cpp:982
+      if (CE)
+        CE->destroyConstant();
       continue;
----------------
A constant can have more than one use?


================
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.
----------------
scui wrote:
> efriedma wrote:
> > scui wrote:
> > > efriedma wrote:
> > > > `VUse.getOperandNo() == 0`?
> > > Thanks for the suggestion. This is the original code as it is, I can change it as you suggested - but looks to me no difference as SI is available.
> > The `SI->getOperand(1)->stripPointerCasts() != GV` seems very suspicious to me; I don't understand why we want to special-case storing the address of a global to itself.
> > 
> > For the `SI->getOperand(0) == V` part, I guess it doesn't really matter.
> I think this is to make sure the malloc site for GV is only for GV.
In case it wasn't clear, I meant, "For the SI->getOperand(0) == V part, I guess it doesn't really matter how you write it.  SI->getOperand(0) == V is essentially equivalent to VUse.getOperandNo() == 0."  

I don't follow your explanation for the `SI->getOperand(1)->stripPointerCasts() != GV` part; can you describe it in a bit more detail?


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

https://reviews.llvm.org/D106589



More information about the llvm-commits mailing list