[llvm] r371556 - [ValueTracking] Factor our common speculation suppression logic [NFC]
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 10 14:12:29 PDT 2019
Author: reames
Date: Tue Sep 10 14:12:29 2019
New Revision: 371556
URL: http://llvm.org/viewvc/llvm-project?rev=371556&view=rev
Log:
[ValueTracking] Factor our common speculation suppression logic [NFC]
Expose a utility function so that all places which want to suppress speculation (when otherwise legal) due to ordering and/or sanitizer interaction can do so.
Modified:
llvm/trunk/include/llvm/Analysis/ValueTracking.h
llvm/trunk/lib/Analysis/ValueTracking.cpp
llvm/trunk/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
Modified: llvm/trunk/include/llvm/Analysis/ValueTracking.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ValueTracking.h?rev=371556&r1=371555&r2=371556&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/ValueTracking.h (original)
+++ llvm/trunk/include/llvm/Analysis/ValueTracking.h Tue Sep 10 14:12:29 2019
@@ -384,6 +384,13 @@ class Value;
/// Return true if the only users of this pointer are lifetime markers.
bool onlyUsedByLifetimeMarkers(const Value *V);
+ /// Return true if speculation of the given load must be suppressed to avoid
+ /// ordering or interfering with an active sanitizer. If not suppressed,
+ /// dereferenceability and alignment must be proven separately. Note: This
+ /// is only needed for raw reasoning; if you use the interface below
+ /// (isSafeToSpeculativelyExecute), this is handled internally.
+ bool mustSuppressSpeculation(const LoadInst &LI);
+
/// Return true if the instruction does not have any effects besides
/// calculating the result and does not have undefined behavior.
///
Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=371556&r1=371555&r2=371556&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp Tue Sep 10 14:12:29 2019
@@ -3877,6 +3877,18 @@ bool llvm::onlyUsedByLifetimeMarkers(con
return true;
}
+bool llvm::mustSuppressSpeculation(const LoadInst &LI) {
+ if (!LI.isUnordered())
+ return true;
+ const Function &F = *LI.getFunction();
+ // Speculative load may create a race that did not exist in the source.
+ return F.hasFnAttribute(Attribute::SanitizeThread) ||
+ // Speculative load may load data from dirty regions.
+ F.hasFnAttribute(Attribute::SanitizeAddress) ||
+ F.hasFnAttribute(Attribute::SanitizeHWAddress);
+}
+
+
bool llvm::isSafeToSpeculativelyExecute(const Value *V,
const Instruction *CtxI,
const DominatorTree *DT) {
@@ -3921,12 +3933,7 @@ bool llvm::isSafeToSpeculativelyExecute(
}
case Instruction::Load: {
const LoadInst *LI = cast<LoadInst>(Inst);
- if (!LI->isUnordered() ||
- // Speculative load may create a race that did not exist in the source.
- LI->getFunction()->hasFnAttribute(Attribute::SanitizeThread) ||
- // Speculative load may load data from dirty regions.
- LI->getFunction()->hasFnAttribute(Attribute::SanitizeAddress) ||
- LI->getFunction()->hasFnAttribute(Attribute::SanitizeHWAddress))
+ if (mustSuppressSpeculation(*LI))
return false;
const DataLayout &DL = LI->getModule()->getDataLayout();
return isDereferenceableAndAlignedPointer(LI->getPointerOperand(),
Modified: llvm/trunk/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp?rev=371556&r1=371555&r2=371556&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp (original)
+++ llvm/trunk/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp Tue Sep 10 14:12:29 2019
@@ -969,21 +969,6 @@ static bool isDereferenceableAndAlignedI
DL, HeaderFirstNonPHI, &DT);
}
-/// Return true if speculation of the given load must be suppressed for
-/// correctness reasons. If not suppressed, dereferenceability and alignment
-/// must be proven.
-/// TODO: Move to ValueTracking.h/cpp in a separate change
-static bool mustSuppressSpeculation(const LoadInst &LI) {
- if (!LI.isUnordered())
- return true;
- const Function &F = *LI.getFunction();
- // Speculative load may create a race that did not exist in the source.
- return F.hasFnAttribute(Attribute::SanitizeThread) ||
- // Speculative load may load data from dirty regions.
- F.hasFnAttribute(Attribute::SanitizeAddress) ||
- F.hasFnAttribute(Attribute::SanitizeHWAddress);
-}
-
bool LoopVectorizationLegality::canVectorizeWithIfConvert() {
if (!EnableIfConversion) {
reportVectorizationFailure("If-conversion is disabled",
More information about the llvm-commits
mailing list