diff options
author | Bill Wendling <isanbard@gmail.com> | 2013-11-25 05:27:31 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2013-11-25 05:27:31 +0000 |
commit | fc1f9531d3f9bf14b4b20b80f158317795d3d1d8 (patch) | |
tree | f7b60c63c91a1a94c4469b0647e7619c976f5275 /lib | |
parent | 91e3564ee7cc478fc3006d6bae5387ba2d46f20c (diff) | |
download | external_llvm-fc1f9531d3f9bf14b4b20b80f158317795d3d1d8.zip external_llvm-fc1f9531d3f9bf14b4b20b80f158317795d3d1d8.tar.gz external_llvm-fc1f9531d3f9bf14b4b20b80f158317795d3d1d8.tar.bz2 |
Merging r195528:
------------------------------------------------------------------------
r195528 | chandlerc | 2013-11-22 16:48:34 -0800 (Fri, 22 Nov 2013) | 7 lines
Migrate metadata information from scalar to vector instructions during
SLP vectorization. Based on the code in BBVectorizer.
Fixes PR17741.
Patch by Raul Silvera, reviewed by Hal and Nadav. Reformatted by my
driving of clang-format. =]
------------------------------------------------------------------------
git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_34@195608 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Transforms/Vectorize/SLPVectorizer.cpp | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/lib/Transforms/Vectorize/SLPVectorizer.cpp b/lib/Transforms/Vectorize/SLPVectorizer.cpp index 2b498a8..f29efad 100644 --- a/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -163,6 +163,37 @@ static unsigned getSameOpcode(ArrayRef<Value *> VL) { return Opcode; } +/// \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 = 0; // Remove unknown metadata + break; + case LLVMContext::MD_tbaa: + MD = MDNode::getMostGenericTBAA(MD, IMD); + break; + case LLVMContext::MD_fpmath: + MD = MDNode::getMostGenericFPMath(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) { @@ -1478,6 +1509,10 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) { BinaryOperator *BinOp = cast<BinaryOperator>(VL0); Value *V = Builder.CreateBinOp(BinOp->getOpcode(), LHS, RHS); E->VectorizedValue = V; + + if (Instruction *I = dyn_cast<Instruction>(V)) + return propagateMetadata(I, E->Scalars); + return V; } case Instruction::Load: { @@ -1494,7 +1529,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) { LI = Builder.CreateLoad(VecPtr); LI->setAlignment(Alignment); E->VectorizedValue = LI; - return LI; + return propagateMetadata(LI, E->Scalars); } case Instruction::Store: { StoreInst *SI = cast<StoreInst>(VL0); @@ -1513,7 +1548,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) { StoreInst *S = Builder.CreateStore(VecValue, VecPtr); S->setAlignment(Alignment); E->VectorizedValue = S; - return S; + return propagateMetadata(S, E->Scalars); } default: llvm_unreachable("unknown inst"); |