Skip to content

Commit aef0fcb

Browse files
committedMar 19, 2017
Extract FindAvailablePtrLoadStore out of FindAvailableLoadedValue. NFCI
Summary: Extract FindAvailablePtrLoadStore out of FindAvailableLoadedValue. Prepare for upcoming change which will do phi-translation for load on phi pointer in jump threading SimplifyPartiallyRedundantLoad. This is in preparation for https://reviews.llvm.org/D30543 Reviewers: efriedma, sanjoy, davide, dberlin Reviewed By: davide Subscribers: junbuml, davide, llvm-commits Differential Revision: https://reviews.llvm.org/D30524 llvm-svn: 298216
1 parent a31ea64 commit aef0fcb

File tree

2 files changed

+46
-14
lines changed

2 files changed

+46
-14
lines changed
 

‎llvm/include/llvm/Analysis/Loads.h

+28
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,34 @@ Value *FindAvailableLoadedValue(LoadInst *Load,
8888
bool *IsLoadCSE = nullptr,
8989
unsigned *NumScanedInst = nullptr);
9090

91+
/// Scan backwards to see if we have the value of the given pointer available
92+
/// locally within a small number of instructions.
93+
///
94+
/// You can use this function to scan across multiple blocks: after you call
95+
/// this function, if ScanFrom points at the beginning of the block, it's safe
96+
/// to continue scanning the predecessors.
97+
///
98+
/// \param Ptr The pointer we want the load and store to originate from.
99+
/// \param AccessTy The access type of the pointer.
100+
/// \param AtLeastAtomic Are we looking for at-least an atomic load/store ? In
101+
/// case it is false, we can return an atomic or non-atomic load or store. In
102+
/// case it is true, we need to return an atomic load or store.
103+
/// \param ScanBB The basic block to scan.
104+
/// \param [in,out] ScanFrom The location to start scanning from. When this
105+
/// function returns, it points at the last instruction scanned.
106+
/// \param MaxInstsToScan The maximum number of instructions to scan. If this
107+
/// is zero, the whole block will be scanned.
108+
/// \param AA Optional pointer to alias analysis, to make the scan more
109+
/// precise.
110+
/// \param [out] IsLoad Whether the returned value is a load from the same
111+
/// location in memory, as opposed to the value operand of a store.
112+
///
113+
/// \returns The found value, or nullptr if no value is found.
114+
Value *FindAvailablePtrLoadStore(Value *Ptr, Type *AccessTy, bool AtLeastAtomic,
115+
BasicBlock *ScanBB,
116+
BasicBlock::iterator &ScanFrom,
117+
unsigned MaxInstsToScan, AliasAnalysis *AA,
118+
bool *IsLoad, unsigned *NumScanedInst);
91119
}
92120

93121
#endif

‎llvm/lib/Analysis/Loads.cpp

+18-14
Original file line numberDiff line numberDiff line change
@@ -312,22 +312,26 @@ Value *llvm::FindAvailableLoadedValue(LoadInst *Load,
312312
BasicBlock *ScanBB,
313313
BasicBlock::iterator &ScanFrom,
314314
unsigned MaxInstsToScan,
315-
AliasAnalysis *AA, bool *IsLoadCSE,
315+
AliasAnalysis *AA, bool *IsLoad,
316316
unsigned *NumScanedInst) {
317-
if (MaxInstsToScan == 0)
318-
MaxInstsToScan = ~0U;
319-
320-
Value *Ptr = Load->getPointerOperand();
321-
Type *AccessTy = Load->getType();
322-
323-
// We can never remove a volatile load
324-
if (Load->isVolatile())
325-
return nullptr;
326-
327-
// Anything stronger than unordered is currently unimplemented.
317+
// Don't CSE load that is volatile or anything stronger than unordered.
328318
if (!Load->isUnordered())
329319
return nullptr;
330320

321+
return FindAvailablePtrLoadStore(
322+
Load->getPointerOperand(), Load->getType(), Load->isAtomic(), ScanBB,
323+
ScanFrom, MaxInstsToScan, AA, IsLoad, NumScanedInst);
324+
}
325+
326+
Value *llvm::FindAvailablePtrLoadStore(Value *Ptr, Type *AccessTy,
327+
bool AtLeastAtomic, BasicBlock *ScanBB,
328+
BasicBlock::iterator &ScanFrom,
329+
unsigned MaxInstsToScan,
330+
AliasAnalysis *AA, bool *IsLoadCSE,
331+
unsigned *NumScanedInst) {
332+
if (MaxInstsToScan == 0)
333+
MaxInstsToScan = ~0U;
334+
331335
const DataLayout &DL = ScanBB->getModule()->getDataLayout();
332336

333337
// Try to get the store size for the type.
@@ -363,7 +367,7 @@ Value *llvm::FindAvailableLoadedValue(LoadInst *Load,
363367

364368
// We can value forward from an atomic to a non-atomic, but not the
365369
// other way around.
366-
if (LI->isAtomic() < Load->isAtomic())
370+
if (LI->isAtomic() < AtLeastAtomic)
367371
return nullptr;
368372

369373
if (IsLoadCSE)
@@ -382,7 +386,7 @@ Value *llvm::FindAvailableLoadedValue(LoadInst *Load,
382386

383387
// We can value forward from an atomic to a non-atomic, but not the
384388
// other way around.
385-
if (SI->isAtomic() < Load->isAtomic())
389+
if (SI->isAtomic() < AtLeastAtomic)
386390
return nullptr;
387391

388392
if (IsLoadCSE)

0 commit comments

Comments
 (0)
Please sign in to comment.