[llvm] LSV: forbid load-cycles when vectorizing; fix bug (PR #104815)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 20 12:20:52 PDT 2024
================
@@ -996,10 +996,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()) {
+ if (isa<PHINode>(O))
+ continue;
+ if (auto *J = dyn_cast<Instruction>(O)) {
+ if (J == ChainBegin) {
----------------
artagnon wrote:
Hm, I originally had this code in the loop below, but had to move it here due to the `std::next` in `BBIt`. Will think about how we can check everything in the chain in elegantly: unfortunately, the function is just passed two `Instruction *`, instead of a first-class chain.
https://github.com/llvm/llvm-project/pull/104815
More information about the llvm-commits
mailing list