[PATCH] D27855: [InstCombine] try to extend nonnull-ness of arguments from a callsite back to its parent function

Michael Kuperstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 16 17:23:41 PST 2016

mkuper added inline comments.

Comment at: lib/Transforms/InstCombine/InstCombineCalls.cpp:2799
+  Instruction *Call = CS.getInstruction();
+  auto CallDominatesOtherUsesOfValue = [&Call, &DT](Value *V) {
+    for (User *U : V->users())
spatel wrote:
> efriedma wrote:
> > I don't think this check is sufficient; consider something like this:
> > 
> > ```
> > void g(int* NONNULL notnull_ptr);
> > void f(int *ptr, bool ptr_is_nonnull) {
> >   if (ptr_is_nonnull) g(ptr);
> > }
> > ```
> > 
> > I think your check marks the "ptr" argument to f() as nonnull.  This deduction gets propagated out to callers of f(), which then assume the pointer isn't null.
> Nice catch. Yes, that would be wrong. We can only do this if the callsite is in the entry block?
I'd say "if the callsite post-dominates the entry block", except that LLVM's notion of post-dominance isn't really strong enough to be useful, IIRC.


More information about the llvm-commits mailing list