[InstCombine] icmp eq/ne (gep inbounds P, Idx..), null -> icmp eq/ne P, null
authorPhilip Reames <listmail@philipreames.com>
Fri, 23 Aug 2019 17:58:58 +0000 (17:58 +0000)
committerPhilip Reames <listmail@philipreames.com>
Fri, 23 Aug 2019 17:58:58 +0000 (17:58 +0000)
commit5b02cfa0b3c2c34943108b02ff2ff45ec46a2af3
treed4a196c406ec33d868b81fd3cb0cafd881105eba
parente7823a53164b0526c9463fc9515f42d5c53651db
[InstCombine] icmp eq/ne (gep inbounds P, Idx..), null -> icmp eq/ne P, null

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.

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.

Differential Revision: https://reviews.llvm.org/D66608

llvm-svn: 369789
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/gep-inbounds-null.ll [new file with mode: 0644]