[PATCH] D102711: [GlobalOpt] Handle null check with global pointer variables

Shimin Cui via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 14 13:19:00 PDT 2021


scui added inline comments.


================
Comment at: llvm/lib/Transforms/IPO/GlobalOpt.cpp:932
+      auto *InitBoolValue = ConstantInt::getBool(
+          GV->getContext(), !GV->hasInitializer() ||
+                                SI->getValueOperand() != GV->getInitializer());
----------------
efriedma wrote:
> scui wrote:
> > efriedma wrote:
> > > I think `GV->hasInitializer()` must be true here?
> > > 
> > > The equality comparison here makes me a little nervous, in case the way we analyze bitcasts changes in the future.  `SI->getValueOperand()->isNullValue()` would probably be more clear anyway.
> > That's right,  GV->hasInitializer() is true here. Modify the code as you suggested. 
> Would `!isa<Constant>(SI->getValueOperand()))` work?
> Would `!isa<Constant>(SI->getValueOperand()))` work?

This won't work, as the "GV = malloc()" instruction has been transformed to "GV = &NewGV", and "&NewGV" is a Constant.


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

https://reviews.llvm.org/D102711



More information about the llvm-commits mailing list