diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Analysis/VectorUtils.cpp | 41 | ||||
-rw-r--r-- | llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 35 | ||||
-rw-r--r-- | llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 40 |
3 files changed, 48 insertions, 68 deletions
diff --git a/llvm/lib/Analysis/VectorUtils.cpp b/llvm/lib/Analysis/VectorUtils.cpp index 5d302d70cc9..53e7153a350 100644 --- a/llvm/lib/Analysis/VectorUtils.cpp +++ b/llvm/lib/Analysis/VectorUtils.cpp @@ -447,3 +447,44 @@ llvm::computeMinimumValueSizes(ArrayRef<BasicBlock *> Blocks, DemandedBits &DB, return MinBWs; } + +/// \returns \p I after propagating metadata from \p VL. +Instruction *llvm::propagateMetadata(Instruction *Inst, ArrayRef<Value *> VL) { + Instruction *I0 = cast<Instruction>(VL[0]); + SmallVector<std::pair<unsigned, MDNode *>, 4> Metadata; + I0->getAllMetadataOtherThanDebugLoc(Metadata); + + for (auto Kind : { LLVMContext::MD_tbaa, LLVMContext::MD_alias_scope, + LLVMContext::MD_noalias, LLVMContext::MD_fpmath, + LLVMContext::MD_nontemporal }) { + MDNode *MD = I0->getMetadata(Kind); + + for (int J = 1, E = VL.size(); MD && J != E; ++J) { + const Instruction *IJ = cast<Instruction>(VL[J]); + MDNode *IMD = IJ->getMetadata(Kind); + switch (Kind) { + case LLVMContext::MD_tbaa: + MD = MDNode::getMostGenericTBAA(MD, IMD); + break; + case LLVMContext::MD_alias_scope: + MD = MDNode::getMostGenericAliasScope(MD, IMD); + break; + case LLVMContext::MD_noalias: + MD = MDNode::intersect(MD, IMD); + break; + case LLVMContext::MD_fpmath: + MD = MDNode::getMostGenericFPMath(MD, IMD); + break; + case LLVMContext::MD_nontemporal: + MD = MDNode::intersect(MD, IMD); + break; + default: + llvm_unreachable("unhandled metadata"); + } + } + + Inst->setMetadata(Kind, MD); + } + + return Inst; +} diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 0463f97e315..e7480d0f15a 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -463,11 +463,11 @@ protected: /// This includes both the original MDs from \p From and additional ones (\see /// addNewMetadata). Use this for *newly created* instructions in the vector /// loop. - void addMetadata(Instruction *To, const Instruction *From); + void addMetadata(Instruction *To, Instruction *From); /// \brief Similar to the previous function but it adds the metadata to a /// vector of instructions. - void addMetadata(SmallVectorImpl<Value *> &To, const Instruction *From); + void addMetadata(ArrayRef<Value *> To, Instruction *From); /// This is a helper class that holds the vectorizer state. It maps scalar /// instructions to vector instructions. When the code is 'unrolled' then @@ -654,28 +654,6 @@ static std::string getDebugLocString(const Loop *L) { } #endif -/// \brief Propagate known metadata from one instruction to another. -static void propagateMetadata(Instruction *To, const Instruction *From) { - SmallVector<std::pair<unsigned, MDNode *>, 4> Metadata; - From->getAllMetadataOtherThanDebugLoc(Metadata); - - for (auto M : Metadata) { - unsigned Kind = M.first; - - // These are safe to transfer (this is safe for TBAA, even when we - // if-convert, because should that metadata have had a control dependency - // on the condition, and thus actually aliased with some other - // non-speculated memory access when the condition was false, this would be - // caught by the runtime overlap checks). - if (Kind != LLVMContext::MD_tbaa && Kind != LLVMContext::MD_alias_scope && - Kind != LLVMContext::MD_noalias && Kind != LLVMContext::MD_fpmath && - Kind != LLVMContext::MD_nontemporal) - continue; - - To->setMetadata(Kind, M.second); - } -} - void InnerLoopVectorizer::addNewMetadata(Instruction *To, const Instruction *Orig) { // If the loop was versioned with memchecks, add the corresponding no-alias @@ -685,16 +663,17 @@ void InnerLoopVectorizer::addNewMetadata(Instruction *To, } void InnerLoopVectorizer::addMetadata(Instruction *To, - const Instruction *From) { + Instruction *From) { propagateMetadata(To, From); addNewMetadata(To, From); } -void InnerLoopVectorizer::addMetadata(SmallVectorImpl<Value *> &To, - const Instruction *From) { - for (Value *V : To) +void InnerLoopVectorizer::addMetadata(ArrayRef<Value *> To, + Instruction *From) { + for (Value *V : To) { if (Instruction *I = dyn_cast<Instruction>(V)) addMetadata(I, From); + } } /// \brief The group of interleaved loads/stores sharing the same stride and diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 4d023c925d2..3f0290faf01 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -220,46 +220,6 @@ static void propagateIRFlags(Value *I, ArrayRef<Value *> VL) { } } -/// \returns \p I after propagating metadata from \p VL. -static Instruction *propagateMetadata(Instruction *I, ArrayRef<Value *> VL) { - Instruction *I0 = cast<Instruction>(VL[0]); - SmallVector<std::pair<unsigned, MDNode *>, 4> Metadata; - I0->getAllMetadataOtherThanDebugLoc(Metadata); - - for (unsigned i = 0, n = Metadata.size(); i != n; ++i) { - unsigned Kind = Metadata[i].first; - MDNode *MD = Metadata[i].second; - - for (int i = 1, e = VL.size(); MD && i != e; i++) { - Instruction *I = cast<Instruction>(VL[i]); - MDNode *IMD = I->getMetadata(Kind); - - switch (Kind) { - default: - MD = nullptr; // Remove unknown metadata - break; - case LLVMContext::MD_tbaa: - MD = MDNode::getMostGenericTBAA(MD, IMD); - break; - case LLVMContext::MD_alias_scope: - MD = MDNode::getMostGenericAliasScope(MD, IMD); - break; - case LLVMContext::MD_noalias: - MD = MDNode::intersect(MD, IMD); - break; - case LLVMContext::MD_fpmath: - MD = MDNode::getMostGenericFPMath(MD, IMD); - break; - case LLVMContext::MD_nontemporal: - MD = MDNode::intersect(MD, IMD); - break; - } - } - I->setMetadata(Kind, MD); - } - return I; -} - /// \returns The type that all of the values in \p VL have or null if there /// are different types. static Type* getSameType(ArrayRef<Value *> VL) { |