Skip to content

Commit ffe82da

Browse files
committed
[NFC][Load] Find better place for mustSuppressSpeculation
And extract `suppressSpeculativeLoadForSanitizers`. Pull Request: #100794
1 parent 0954205 commit ffe82da

File tree

4 files changed

+20
-18
lines changed

4 files changed

+20
-18
lines changed

llvm/include/llvm/Analysis/Loads.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ bool isSafeToLoadUnconditionally(Value *V, Type *Ty, Align Alignment,
106106
const DominatorTree *DT = nullptr,
107107
const TargetLibraryInfo *TLI = nullptr);
108108

109+
/// Return true if speculation of the given load must be suppressed to avoid
110+
/// ordering or interfering with an active sanitizer. If not suppressed,
111+
/// dereferenceability and alignment must be proven separately. Note: This
112+
/// is only needed for raw reasoning; if you use the interface below
113+
/// (isSafeToSpeculativelyExecute), this is handled internally.
114+
bool mustSuppressSpeculation(const LoadInst &LI);
115+
109116
/// The default number of maximum instructions to scan in the block, used by
110117
/// FindAvailableLoadedValue().
111118
extern cl::opt<unsigned> DefMaxInstsToScan;

llvm/include/llvm/Analysis/ValueTracking.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -792,13 +792,6 @@ bool onlyUsedByLifetimeMarkers(const Value *V);
792792
/// droppable instructions.
793793
bool onlyUsedByLifetimeMarkersOrDroppableInsts(const Value *V);
794794

795-
/// Return true if speculation of the given load must be suppressed to avoid
796-
/// ordering or interfering with an active sanitizer. If not suppressed,
797-
/// dereferenceability and alignment must be proven separately. Note: This
798-
/// is only needed for raw reasoning; if you use the interface below
799-
/// (isSafeToSpeculativelyExecute), this is handled internally.
800-
bool mustSuppressSpeculation(const LoadInst &LI);
801-
802795
/// Return true if the instruction does not have any effects besides
803796
/// calculating the result and does not have undefined behavior.
804797
///

llvm/lib/Analysis/Loads.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,19 @@ bool llvm::isDereferenceableAndAlignedInLoop(LoadInst *LI, Loop *L,
345345
HeaderFirstNonPHI, AC, &DT);
346346
}
347347

348+
static bool suppressSpeculativeLoadForSanitizers(const Instruction &CtxI) {
349+
const Function &F = *CtxI.getFunction();
350+
// Speculative load may create a race that did not exist in the source.
351+
return F.hasFnAttribute(Attribute::SanitizeThread) ||
352+
// Speculative load may load data from dirty regions.
353+
F.hasFnAttribute(Attribute::SanitizeAddress) ||
354+
F.hasFnAttribute(Attribute::SanitizeHWAddress);
355+
}
356+
357+
bool llvm::mustSuppressSpeculation(const LoadInst &LI) {
358+
return !LI.isUnordered() || suppressSpeculativeLoadForSanitizers(LI);
359+
}
360+
348361
/// Check if executing a load of this pointer value cannot trap.
349362
///
350363
/// If DT and ScanFrom are specified this method performs context-sensitive

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6798,17 +6798,6 @@ bool llvm::onlyUsedByLifetimeMarkersOrDroppableInsts(const Value *V) {
67986798
V, /* AllowLifetime */ true, /* AllowDroppable */ true);
67996799
}
68006800

6801-
bool llvm::mustSuppressSpeculation(const LoadInst &LI) {
6802-
if (!LI.isUnordered())
6803-
return true;
6804-
const Function &F = *LI.getFunction();
6805-
// Speculative load may create a race that did not exist in the source.
6806-
return F.hasFnAttribute(Attribute::SanitizeThread) ||
6807-
// Speculative load may load data from dirty regions.
6808-
F.hasFnAttribute(Attribute::SanitizeAddress) ||
6809-
F.hasFnAttribute(Attribute::SanitizeHWAddress);
6810-
}
6811-
68126801
bool llvm::isSafeToSpeculativelyExecute(const Instruction *Inst,
68136802
const Instruction *CtxI,
68146803
AssumptionCache *AC,

0 commit comments

Comments
 (0)