Skip to content

Commit 89dae79

Browse files
committed
[Loads] Use BatchAAResults for available value APIs (NFCI)
This allows caching AA queries both within and across the calls, and enables us to use a custom AAQI configuration.
1 parent 7fdf608 commit 89dae79

File tree

5 files changed

+20
-18
lines changed

5 files changed

+20
-18
lines changed

llvm/include/llvm/Analysis/Loads.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
namespace llvm {
2020

21-
class AAResults;
21+
class BatchAAResults;
2222
class AssumptionCache;
2323
class DataLayout;
2424
class DominatorTree;
@@ -129,19 +129,19 @@ extern cl::opt<unsigned> DefMaxInstsToScan;
129129
/// location in memory, as opposed to the value operand of a store.
130130
///
131131
/// \returns The found value, or nullptr if no value is found.
132-
Value *FindAvailableLoadedValue(LoadInst *Load,
133-
BasicBlock *ScanBB,
132+
Value *FindAvailableLoadedValue(LoadInst *Load, BasicBlock *ScanBB,
134133
BasicBlock::iterator &ScanFrom,
135134
unsigned MaxInstsToScan = DefMaxInstsToScan,
136-
AAResults *AA = nullptr,
135+
BatchAAResults *AA = nullptr,
137136
bool *IsLoadCSE = nullptr,
138137
unsigned *NumScanedInst = nullptr);
139138

140139
/// This overload provides a more efficient implementation of
141140
/// FindAvailableLoadedValue() for the case where we are not interested in
142141
/// finding the closest clobbering instruction if no available load is found.
143142
/// This overload cannot be used to scan across multiple blocks.
144-
Value *FindAvailableLoadedValue(LoadInst *Load, AAResults &AA, bool *IsLoadCSE,
143+
Value *FindAvailableLoadedValue(LoadInst *Load, BatchAAResults &AA,
144+
bool *IsLoadCSE,
145145
unsigned MaxInstsToScan = DefMaxInstsToScan);
146146

147147
/// Scan backwards to see if we have the value of the given pointer available
@@ -170,7 +170,7 @@ Value *FindAvailableLoadedValue(LoadInst *Load, AAResults &AA, bool *IsLoadCSE,
170170
Value *findAvailablePtrLoadStore(const MemoryLocation &Loc, Type *AccessTy,
171171
bool AtLeastAtomic, BasicBlock *ScanBB,
172172
BasicBlock::iterator &ScanFrom,
173-
unsigned MaxInstsToScan, AAResults *AA,
173+
unsigned MaxInstsToScan, BatchAAResults *AA,
174174
bool *IsLoadCSE, unsigned *NumScanedInst);
175175

176176
/// Returns true if a pointer value \p A can be replace with another pointer

llvm/lib/Analysis/Lint.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,11 +657,12 @@ Value *Lint::findValueImpl(Value *V, bool OffsetOk,
657657
BasicBlock::iterator BBI = L->getIterator();
658658
BasicBlock *BB = L->getParent();
659659
SmallPtrSet<BasicBlock *, 4> VisitedBlocks;
660+
BatchAAResults BatchAA(*AA);
660661
for (;;) {
661662
if (!VisitedBlocks.insert(BB).second)
662663
break;
663664
if (Value *U =
664-
FindAvailableLoadedValue(L, BB, BBI, DefMaxInstsToScan, AA))
665+
FindAvailableLoadedValue(L, BB, BBI, DefMaxInstsToScan, &BatchAA))
665666
return findValueImpl(U, OffsetOk, Visited);
666667
if (BBI != BB->begin())
667668
break;

llvm/lib/Analysis/Loads.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -450,11 +450,10 @@ llvm::DefMaxInstsToScan("available-load-scan-limit", cl::init(6), cl::Hidden,
450450
"to scan backward from a given instruction, when searching for "
451451
"available loaded value"));
452452

453-
Value *llvm::FindAvailableLoadedValue(LoadInst *Load,
454-
BasicBlock *ScanBB,
453+
Value *llvm::FindAvailableLoadedValue(LoadInst *Load, BasicBlock *ScanBB,
455454
BasicBlock::iterator &ScanFrom,
456455
unsigned MaxInstsToScan,
457-
AAResults *AA, bool *IsLoad,
456+
BatchAAResults *AA, bool *IsLoad,
458457
unsigned *NumScanedInst) {
459458
// Don't CSE load that is volatile or anything stronger than unordered.
460459
if (!Load->isUnordered())
@@ -583,7 +582,7 @@ static Value *getAvailableLoadStore(Instruction *Inst, const Value *Ptr,
583582
Value *llvm::findAvailablePtrLoadStore(
584583
const MemoryLocation &Loc, Type *AccessTy, bool AtLeastAtomic,
585584
BasicBlock *ScanBB, BasicBlock::iterator &ScanFrom, unsigned MaxInstsToScan,
586-
AAResults *AA, bool *IsLoadCSE, unsigned *NumScanedInst) {
585+
BatchAAResults *AA, bool *IsLoadCSE, unsigned *NumScanedInst) {
587586
if (MaxInstsToScan == 0)
588587
MaxInstsToScan = ~0U;
589588

@@ -664,7 +663,7 @@ Value *llvm::findAvailablePtrLoadStore(
664663
return nullptr;
665664
}
666665

667-
Value *llvm::FindAvailableLoadedValue(LoadInst *Load, AAResults &AA,
666+
Value *llvm::FindAvailableLoadedValue(LoadInst *Load, BatchAAResults &AA,
668667
bool *IsLoadCSE,
669668
unsigned MaxInstsToScan) {
670669
const DataLayout &DL = Load->getModule()->getDataLayout();

llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,8 @@ Instruction *InstCombinerImpl::visitLoadInst(LoadInst &LI) {
10321032
// where there are several consecutive memory accesses to the same location,
10331033
// separated by a few arithmetic operations.
10341034
bool IsLoadCSE = false;
1035-
if (Value *AvailableVal = FindAvailableLoadedValue(&LI, *AA, &IsLoadCSE)) {
1035+
BatchAAResults BatchAA(*AA);
1036+
if (Value *AvailableVal = FindAvailableLoadedValue(&LI, BatchAA, &IsLoadCSE)) {
10361037
if (IsLoadCSE)
10371038
combineMetadataForCSE(cast<LoadInst>(AvailableVal), &LI, false);
10381039

llvm/lib/Transforms/Scalar/JumpThreading.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,8 +1260,9 @@ bool JumpThreadingPass::simplifyPartiallyRedundantLoad(LoadInst *LoadI) {
12601260
// the entry to its block.
12611261
BasicBlock::iterator BBIt(LoadI);
12621262
bool IsLoadCSE;
1263+
BatchAAResults BatchAA(*AA);
12631264
if (Value *AvailableVal = FindAvailableLoadedValue(
1264-
LoadI, LoadBB, BBIt, DefMaxInstsToScan, AA, &IsLoadCSE)) {
1265+
LoadI, LoadBB, BBIt, DefMaxInstsToScan, &BatchAA, &IsLoadCSE)) {
12651266
// If the value of the load is locally available within the block, just use
12661267
// it. This frequently occurs for reg2mem'd allocas.
12671268

@@ -1322,9 +1323,9 @@ bool JumpThreadingPass::simplifyPartiallyRedundantLoad(LoadInst *LoadI) {
13221323
MemoryLocation Loc(LoadedPtr->DoPHITranslation(LoadBB, PredBB),
13231324
LocationSize::precise(DL.getTypeStoreSize(AccessTy)),
13241325
AATags);
1325-
PredAvailable = findAvailablePtrLoadStore(Loc, AccessTy, LoadI->isAtomic(),
1326-
PredBB, BBIt, DefMaxInstsToScan,
1327-
AA, &IsLoadCSE, &NumScanedInst);
1326+
PredAvailable = findAvailablePtrLoadStore(
1327+
Loc, AccessTy, LoadI->isAtomic(), PredBB, BBIt, DefMaxInstsToScan,
1328+
&BatchAA, &IsLoadCSE, &NumScanedInst);
13281329

13291330
// If PredBB has a single predecessor, continue scanning through the
13301331
// single predecessor.
@@ -1336,7 +1337,7 @@ bool JumpThreadingPass::simplifyPartiallyRedundantLoad(LoadInst *LoadI) {
13361337
BBIt = SinglePredBB->end();
13371338
PredAvailable = findAvailablePtrLoadStore(
13381339
Loc, AccessTy, LoadI->isAtomic(), SinglePredBB, BBIt,
1339-
(DefMaxInstsToScan - NumScanedInst), AA, &IsLoadCSE,
1340+
(DefMaxInstsToScan - NumScanedInst), &BatchAA, &IsLoadCSE,
13401341
&NumScanedInst);
13411342
}
13421343
}

0 commit comments

Comments
 (0)