From f85f5da3b2acfde2ff8a83a917db9ae1319329c2 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Tue, 24 Apr 2018 15:28:47 +0000 Subject: [LoadStoreVectorize] Ignore interleaved invariant loads. The memory location an invariant load is using can never be clobbered by any store, so it's safe to move the load ahead of the store. Differential Revision: https://reviews.llvm.org/D46011 llvm-svn: 330725 --- llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp') diff --git a/llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp b/llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp index 2e4707f916d..c1d3f925515 100644 --- a/llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp @@ -562,20 +562,28 @@ Vectorizer::getVectorizablePrefix(ArrayRef Chain) { if (BarrierMemoryInstr && OBB.dominates(BarrierMemoryInstr, MemInstr)) break; - if (isa(MemInstr) && isa(ChainInstr)) + auto *MemLoad = dyn_cast(MemInstr); + auto *ChainLoad = dyn_cast(ChainInstr); + if (MemLoad && ChainLoad) continue; + // We can ignore the alias if the we have a load store pair and the load + // is known to be invariant. The load cannot be clobbered by the store. + auto IsInvariantLoad = [](const LoadInst *LI) -> bool { + return LI->getMetadata(LLVMContext::MD_invariant_load); + }; + // We can ignore the alias as long as the load comes before the store, // because that means we won't be moving the load past the store to // vectorize it (the vectorized load is inserted at the location of the // first load in the chain). - if (isa(MemInstr) && isa(ChainInstr) && - OBB.dominates(ChainInstr, MemInstr)) + if (isa(MemInstr) && ChainLoad && + (IsInvariantLoad(ChainLoad) || OBB.dominates(ChainLoad, MemInstr))) continue; // Same case, but in reverse. - if (isa(MemInstr) && isa(ChainInstr) && - OBB.dominates(MemInstr, ChainInstr)) + if (MemLoad && isa(ChainInstr) && + (IsInvariantLoad(MemLoad) || OBB.dominates(MemLoad, ChainInstr))) continue; if (!AA.isNoAlias(MemoryLocation::get(MemInstr), -- cgit v1.2.3