diff options
| author | Johannes Doerfert <jdoerfert@anl.gov> | 2019-10-13 20:48:26 +0000 |
|---|---|---|
| committer | Johannes Doerfert <jdoerfert@anl.gov> | 2019-10-13 20:48:26 +0000 |
| commit | d82385b0491385a01f5bc2216f8fc72a6521746e (patch) | |
| tree | b47782cca7f9bad33fd122eba09c725b72696545 /llvm/lib/Transforms/IPO/Attributor.cpp | |
| parent | 8ee410c75ec416ea02dabeddd03fb062ab5dc92e (diff) | |
| download | bcm5719-llvm-d82385b0491385a01f5bc2216f8fc72a6521746e.tar.gz bcm5719-llvm-d82385b0491385a01f5bc2216f8fc72a6521746e.zip | |
[Attributor][FIX] NullPointerIsDefined needs the pointer AS (AANonNull)
Also includes a shortcut via AADereferenceable if possible.
llvm-svn: 374737
Diffstat (limited to 'llvm/lib/Transforms/IPO/Attributor.cpp')
| -rw-r--r-- | llvm/lib/Transforms/IPO/Attributor.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp index d7c49a248de..7dfc802179c 100644 --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -1588,11 +1588,16 @@ static int64_t getKnownNonNullAndDerefBytesForUse( } struct AANonNullImpl : AANonNull { - AANonNullImpl(const IRPosition &IRP) : AANonNull(IRP) {} + AANonNullImpl(const IRPosition &IRP) + : AANonNull(IRP), + NullIsDefined(NullPointerIsDefined( + getAnchorScope(), + getAssociatedValue().getType()->getPointerAddressSpace())) {} /// See AbstractAttribute::initialize(...). void initialize(Attributor &A) override { - if (hasAttr({Attribute::NonNull, Attribute::Dereferenceable})) + if (!NullIsDefined && + hasAttr({Attribute::NonNull, Attribute::Dereferenceable})) indicateOptimisticFixpoint(); else AANonNull::initialize(A); @@ -1612,6 +1617,10 @@ struct AANonNullImpl : AANonNull { const std::string getAsStr() const override { return getAssumed() ? "nonnull" : "may-null"; } + + /// Flag to determine if the underlying value can be null and still allow + /// valid accesses. + const bool NullIsDefined; }; /// NonNull attribute for a floating value. @@ -1644,6 +1653,12 @@ struct AANonNullFloating if (isKnownNonNull()) return Change; + if (!NullIsDefined) { + const auto &DerefAA = A.getAAFor<AADereferenceable>(*this, getIRPosition()); + if (DerefAA.getAssumedDereferenceableBytes()) + return Change; + } + const DataLayout &DL = A.getDataLayout(); auto VisitValueCB = [&](Value &V, AAAlign::StateType &T, @@ -1651,7 +1666,7 @@ struct AANonNullFloating const auto &AA = A.getAAFor<AANonNull>(*this, IRPosition::value(V)); if (!Stripped && this == &AA) { if (!isKnownNonZero(&V, DL, 0, /* TODO: AC */ nullptr, - /* TODO: CtxI */ nullptr, + /* CtxI */ getCtxI(), /* TODO: DT */ nullptr)) T.indicatePessimisticFixpoint(); } else { |

