[PATCH] D66608: [InstCombine] icmp eq/ne (gep P, Idx..), null -> icmp eq/ne P, null

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 22 11:06:23 PDT 2019


reames created this revision.
reames added reviewers: jdoerfert, grandinj, nikic.
Herald added subscribers: bollu, mcrosier.
Herald added a project: LLVM.
reames updated this revision to Diff 216674.
reames added a comment.

Fix a typo in one of the tests and add clarifying comments.


This generalizes the isGEPKnownNonNull rule from ValueTracking to apply when we do not know if the base is non-null, and thus need to replace one condition with another.

This is an alternative, much more aggressive, approach to the same problem as https://reviews.llvm.org/D64533.

The core notion is that since an inbounds GEP can only form null if the base pointer is null and the offset is zero.  However, if the offset is non-zero, the the "inbounds" marker makes the result poison.  Thus, we're free to ignore the case where the offset is non-zero.  Similarly, there's no case under which a non-null base can result in a null result without generating poison.

Reviewers - I'd appreciate careful review of the reasoning here.  It's subtle, and I found several bugs in early versions of this patch.  I'm not at all certain there aren't some left.


https://reviews.llvm.org/D66608

Files:
  lib/Transforms/InstCombine/InstCombineCompares.cpp
  test/Transforms/InstCombine/gep-inbounds-null.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66608.216674.patch
Type: text/x-patch
Size: 6621 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190822/15fddfa0/attachment-0001.bin>


More information about the llvm-commits mailing list