Skip to content

Commit 7ad2108

Browse files
committed
[LoadStoreVectorizer] Batch alias analysis results to improve compile time
1 parent bbefd33 commit 7ad2108

File tree

2 files changed

+2595
-5
lines changed

2 files changed

+2595
-5
lines changed

llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ class Vectorizer {
322322
template <bool IsLoadChain>
323323
bool isSafeToMove(
324324
Instruction *ChainElem, Instruction *ChainBegin,
325-
const DenseMap<Instruction *, APInt /*OffsetFromLeader*/> &ChainOffsets);
325+
const DenseMap<Instruction *, APInt /*OffsetFromLeader*/> &ChainOffsets,
326+
BatchAAResults &BatchAA);
326327

327328
/// Merges the equivalence classes if they have underlying objects that differ
328329
/// by one level of indirection (i.e., one is a getelementptr and the other is
@@ -543,6 +544,10 @@ std::vector<Chain> Vectorizer::splitChainByMayAliasInstrs(Chain &C) {
543544
for (const auto &E : C)
544545
ChainOffsets.insert({&*E.Inst, E.OffsetFromLeader});
545546

547+
// Across a single invocation of this function the IR is not changing, so
548+
// using a batched Alias Analysis is safe and can reduce compile time.
549+
BatchAAResults BatchAA(AA);
550+
546551
// Loads get hoisted up to the first load in the chain. Stores get sunk
547552
// down to the last store in the chain. Our algorithm for loads is:
548553
//
@@ -569,7 +574,7 @@ std::vector<Chain> Vectorizer::splitChainByMayAliasInstrs(Chain &C) {
569574
NewChain.emplace_back(*ChainBegin);
570575
for (auto ChainIt = std::next(ChainBegin); ChainIt != ChainEnd; ++ChainIt) {
571576
if (isSafeToMove<IsLoad>(ChainIt->Inst, NewChain.front().Inst,
572-
ChainOffsets)) {
577+
ChainOffsets, BatchAA)) {
573578
LLVM_DEBUG(dbgs() << "LSV: No intervening may-alias instrs; can merge "
574579
<< *ChainIt->Inst << " into " << *ChainBegin->Inst
575580
<< "\n");
@@ -999,7 +1004,8 @@ bool Vectorizer::vectorizeChain(Chain &C) {
9991004
template <bool IsLoadChain>
10001005
bool Vectorizer::isSafeToMove(
10011006
Instruction *ChainElem, Instruction *ChainBegin,
1002-
const DenseMap<Instruction *, APInt /*OffsetFromLeader*/> &ChainOffsets) {
1007+
const DenseMap<Instruction *, APInt /*OffsetFromLeader*/> &ChainOffsets,
1008+
BatchAAResults &BatchAA) {
10031009
LLVM_DEBUG(dbgs() << "LSV: isSafeToMove(" << *ChainElem << " -> "
10041010
<< *ChainBegin << ")\n");
10051011

@@ -1066,7 +1072,8 @@ bool Vectorizer::isSafeToMove(
10661072
LLVM_DEBUG({
10671073
// Double check that AA also sees this alias. If not, we probably
10681074
// have a bug.
1069-
ModRefInfo MR = AA.getModRefInfo(I, MemoryLocation::get(ChainElem));
1075+
ModRefInfo MR =
1076+
BatchAA.getModRefInfo(I, MemoryLocation::get(ChainElem));
10701077
assert(IsLoadChain ? isModSet(MR) : isModOrRefSet(MR));
10711078
dbgs() << "LSV: Found alias in chain: " << *I << "\n";
10721079
});
@@ -1077,7 +1084,7 @@ bool Vectorizer::isSafeToMove(
10771084
}
10781085

10791086
LLVM_DEBUG(dbgs() << "LSV: Querying AA for " << *I << "\n");
1080-
ModRefInfo MR = AA.getModRefInfo(I, MemoryLocation::get(ChainElem));
1087+
ModRefInfo MR = BatchAA.getModRefInfo(I, MemoryLocation::get(ChainElem));
10811088
if (IsLoadChain ? isModSet(MR) : isModOrRefSet(MR)) {
10821089
LLVM_DEBUG(dbgs() << "LSV: Found alias in chain:\n"
10831090
<< " Aliasing instruction:\n"

0 commit comments

Comments
 (0)