-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LSV: forbid load-cycles when vectorizing; fix bug (#104815)
Forbid load-load cycles which would crash LoadStoreVectorizer when reordering instructions. Fixes #37865.
- Loading branch information
Showing
2 changed files
with
98 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -998,10 +998,32 @@ bool Vectorizer::isSafeToMove( | |
LLVM_DEBUG(dbgs() << "LSV: isSafeToMove(" << *ChainElem << " -> " | ||
<< *ChainBegin << ")\n"); | ||
|
||
assert(isa<LoadInst>(ChainElem) == IsLoadChain); | ||
assert(isa<LoadInst>(ChainElem) == IsLoadChain && | ||
isa<LoadInst>(ChainBegin) == IsLoadChain); | ||
|
||
if (ChainElem == ChainBegin) | ||
return true; | ||
|
||
if constexpr (IsLoadChain) { | ||
// If ChainElem depends on ChainBegin, they're not safe to reorder. | ||
SmallVector<Instruction *, 8> Worklist; | ||
Worklist.emplace_back(ChainElem); | ||
while (!Worklist.empty()) { | ||
Instruction *I = Worklist.pop_back_val(); | ||
for (Use &O : I->operands()) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
fhahn
Contributor
|
||
if (isa<PHINode>(O)) | ||
continue; | ||
if (auto *J = dyn_cast<Instruction>(O)) { | ||
if (J == ChainBegin) { | ||
LLVM_DEBUG(dbgs() << "LSV: dependent loads; not safe to reorder\n"); | ||
return false; | ||
} | ||
Worklist.emplace_back(J); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Invariant loads can always be reordered; by definition they are not | ||
// clobbered by stores. | ||
if (isInvariantLoad(ChainElem)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Could we do some caching here? This walk is causing some of our tests to time out (e.g. this test here https://github.com/google/jax/blob/main/tests/random_lax_test.py#L1309).
E.g. the following code would visit %x0 2^20 times, but a single visit is enough to determine whether it's ok