[llvm] r368993 - [ValueTracking] Add MustPreserveNullness arg to functions analyzing calls. (NFC)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 15 05:13:02 PDT 2019
Author: fhahn
Date: Thu Aug 15 05:13:02 2019
New Revision: 368993
URL: http://llvm.org/viewvc/llvm-project?rev=368993&view=rev
Log:
[ValueTracking] Add MustPreserveNullness arg to functions analyzing calls. (NFC)
Some uses of getArgumentAliasingToReturnedPointer and
isIntrinsicReturningPointerAliasingArgumentWithoutCapturing require the
calls/intrinsics to preserve the nullness of the argument.
For alias analysis, the nullness property does not really come into
play.
This patch explicitly sets it to true. In D61669, the alias analysis
uses will be switched to not require preserving nullness.
Reviewers: nlopes, efriedma, hfinkel, sanjoy, aqjune, jdoerfert
Reviewed By: jdoerfert
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D64150
Modified:
llvm/trunk/include/llvm/Analysis/ValueTracking.h
llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
llvm/trunk/lib/Analysis/CaptureTracking.cpp
llvm/trunk/lib/Analysis/Loads.cpp
llvm/trunk/lib/Analysis/ValueTracking.cpp
Modified: llvm/trunk/include/llvm/Analysis/ValueTracking.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ValueTracking.h?rev=368993&r1=368992&r2=368993&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/ValueTracking.h (original)
+++ llvm/trunk/include/llvm/Analysis/ValueTracking.h Thu Aug 15 05:13:02 2019
@@ -307,20 +307,26 @@ class Value;
uint64_t GetStringLength(const Value *V, unsigned CharSize = 8);
/// This function returns call pointer argument that is considered the same by
- /// aliasing rules. You CAN'T use it to replace one value with another.
- const Value *getArgumentAliasingToReturnedPointer(const CallBase *Call);
- inline Value *getArgumentAliasingToReturnedPointer(CallBase *Call) {
+ /// aliasing rules. You CAN'T use it to replace one value with another. If
+ /// \p MustPreserveNullness is true, the call must preserve the nullness of
+ /// the pointer.
+ const Value *getArgumentAliasingToReturnedPointer(const CallBase *Call,
+ bool MustPreserveNullness);
+ inline Value *
+ getArgumentAliasingToReturnedPointer(CallBase *Call,
+ bool MustPreserveNullness) {
return const_cast<Value *>(getArgumentAliasingToReturnedPointer(
- const_cast<const CallBase *>(Call)));
+ const_cast<const CallBase *>(Call), MustPreserveNullness));
}
- // {launder,strip}.invariant.group returns pointer that aliases its argument,
- // and it only captures pointer by returning it.
- // These intrinsics are not marked as nocapture, because returning is
- // considered as capture. The arguments are not marked as returned neither,
- // because it would make it useless.
+ /// {launder,strip}.invariant.group returns pointer that aliases its argument,
+ /// and it only captures pointer by returning it.
+ /// These intrinsics are not marked as nocapture, because returning is
+ /// considered as capture. The arguments are not marked as returned neither,
+ /// because it would make it useless. If \p MustPreserveNullness is true,
+ /// the intrinsic must preserve the nullness of the pointer.
bool isIntrinsicReturningPointerAliasingArgumentWithoutCapturing(
- const CallBase *Call);
+ const CallBase *Call, bool MustPreserveNullness);
/// This method strips off any GEP address adjustments and pointer casts from
/// the specified value, returning the original object being addressed. Note
Modified: llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp?rev=368993&r1=368992&r2=368993&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp Thu Aug 15 05:13:02 2019
@@ -481,7 +481,7 @@ bool BasicAAResult::DecomposeGEPExpressi
// because it should be in sync with CaptureTracking. Not using it may
// cause weird miscompilations where 2 aliasing pointers are assumed to
// noalias.
- if (auto *RP = getArgumentAliasingToReturnedPointer(Call)) {
+ if (auto *RP = getArgumentAliasingToReturnedPointer(Call, true)) {
V = RP;
continue;
}
Modified: llvm/trunk/lib/Analysis/CaptureTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/CaptureTracking.cpp?rev=368993&r1=368992&r2=368993&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/CaptureTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/CaptureTracking.cpp Thu Aug 15 05:13:02 2019
@@ -251,7 +251,8 @@ void llvm::PointerMayBeCaptured(const Va
// marked with nocapture do not capture. This means that places like
// GetUnderlyingObject in ValueTracking or DecomposeGEPExpression
// in BasicAA also need to know about this property.
- if (isIntrinsicReturningPointerAliasingArgumentWithoutCapturing(Call)) {
+ if (isIntrinsicReturningPointerAliasingArgumentWithoutCapturing(Call,
+ true)) {
AddUses(Call);
break;
}
Modified: llvm/trunk/lib/Analysis/Loads.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/Loads.cpp?rev=368993&r1=368992&r2=368993&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/Loads.cpp (original)
+++ llvm/trunk/lib/Analysis/Loads.cpp Thu Aug 15 05:13:02 2019
@@ -107,7 +107,7 @@ static bool isDereferenceableAndAlignedP
DL, CtxI, DT, Visited);
if (const auto *Call = dyn_cast<CallBase>(V))
- if (auto *RP = getArgumentAliasingToReturnedPointer(Call))
+ if (auto *RP = getArgumentAliasingToReturnedPointer(Call, true))
return isDereferenceableAndAlignedPointer(RP, Align, Size, DL, CtxI, DT,
Visited);
Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=368993&r1=368992&r2=368993&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp Thu Aug 15 05:13:02 2019
@@ -2073,7 +2073,7 @@ bool isKnownNonZero(const Value *V, unsi
if (const auto *Call = dyn_cast<CallBase>(V)) {
if (Call->isReturnNonNull())
return true;
- if (const auto *RP = getArgumentAliasingToReturnedPointer(Call))
+ if (const auto *RP = getArgumentAliasingToReturnedPointer(Call, true))
return isKnownNonZero(RP, Depth, Q);
}
}
@@ -3658,19 +3658,22 @@ uint64_t llvm::GetStringLength(const Val
return Len == ~0ULL ? 1 : Len;
}
-const Value *llvm::getArgumentAliasingToReturnedPointer(const CallBase *Call) {
+const Value *
+llvm::getArgumentAliasingToReturnedPointer(const CallBase *Call,
+ bool MustPreserveNullness) {
assert(Call &&
"getArgumentAliasingToReturnedPointer only works on nonnull calls");
if (const Value *RV = Call->getReturnedArgOperand())
return RV;
// This can be used only as a aliasing property.
- if (isIntrinsicReturningPointerAliasingArgumentWithoutCapturing(Call))
+ if (isIntrinsicReturningPointerAliasingArgumentWithoutCapturing(
+ Call, MustPreserveNullness))
return Call->getArgOperand(0);
return nullptr;
}
bool llvm::isIntrinsicReturningPointerAliasingArgumentWithoutCapturing(
- const CallBase *Call) {
+ const CallBase *Call, bool MustPreserveNullness) {
return Call->getIntrinsicID() == Intrinsic::launder_invariant_group ||
Call->getIntrinsicID() == Intrinsic::strip_invariant_group ||
Call->getIntrinsicID() == Intrinsic::aarch64_irg ||
@@ -3732,7 +3735,7 @@ Value *llvm::GetUnderlyingObject(Value *
// because it should be in sync with CaptureTracking. Not using it may
// cause weird miscompilations where 2 aliasing pointers are assumed to
// noalias.
- if (auto *RP = getArgumentAliasingToReturnedPointer(Call)) {
+ if (auto *RP = getArgumentAliasingToReturnedPointer(Call, true)) {
V = RP;
continue;
}
More information about the llvm-commits
mailing list