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

Shimin Cui via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 30 14:41:38 PDT 2021


scui added inline comments.


================
Comment at: llvm/lib/Transforms/IPO/GlobalOpt.cpp:735
+        // Ignore stores to the global.
+        if (SI->getPointerOperand() != P)
+          return false;
----------------
efriedma wrote:
> scui wrote:
> > efriedma wrote:
> > > Instead of `SI->getPointerOperand() != P`, should be `SI->getValueOperand() == P`?
> > SI->getPointerOperand() != P is alright. It's ok to store into global (actually the StoredOnce).
> My concern is that with opaque pointers, it will become possible to write something like `store ptr @g, ptr @g`, at which point the difference between `SI->getPointerOperand() != P` and `SI->getValueOperand() == P` will start to matter.
When this function is called, we know there is only one store to the global, and it is from malloc. There are no other stores to the global. So we don't need to worry about "store @g @g". 


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

https://reviews.llvm.org/D106589



More information about the llvm-commits mailing list