diff options
author | Danila Kutenin <kutdanila@yandex.ru> | 2019-12-11 20:30:54 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-12-11 20:32:29 +0100 |
commit | 19e83a9b4cd4b0c2918d975f52bdfc6ba82d839f (patch) | |
tree | cd90f953f3fd52dc0da4bc9e5823414bef8371c2 /llvm/lib/Analysis/ValueTracking.cpp | |
parent | fc765698e0c23c18732255fc7cc0f98160b66a90 (diff) | |
download | bcm5719-llvm-19e83a9b4cd4b0c2918d975f52bdfc6ba82d839f.tar.gz bcm5719-llvm-19e83a9b4cd4b0c2918d975f52bdfc6ba82d839f.zip |
[ValueTracking] Pointer is known nonnull after load/store
If the pointer was loaded/stored before the null check, the check
is redundant and can be removed. For now the optimizers do not
remove the nullptr check, see https://gcc.godbolt.org/z/H2r5GG.
The patch allows to use more nonnull constraints. Also, it found
one more optimization in some PowerPC test. This is my first llvm
review, I am free to any comments.
Differential Revision: https://reviews.llvm.org/D71177
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index e35b235b0bb..0d15187f575 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -1943,6 +1943,15 @@ static bool isKnownNonNullFromDominatingCondition(const Value *V, Arg.hasNonNullAttr() && DT->dominates(CS.getInstruction(), CtxI)) return true; + // If the value is used as a load/store, then the pointer must be non null. + if (V == getLoadStorePointerOperand(U)) { + const Instruction *I = cast<Instruction>(U); + if (!NullPointerIsDefined(I->getFunction(), + V->getType()->getPointerAddressSpace()) && + DT->dominates(I, CtxI)) + return true; + } + // Consider only compare instructions uniquely controlling a branch CmpInst::Predicate Pred; if (!match(const_cast<User *>(U), |