Skip to content

Instantly share code, notes, and snippets.

/-

Created June 10, 2016 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/7219541341dd9029d0c038ec59246f8b to your computer and use it in GitHub Desktop.
Save anonymous/7219541341dd9029d0c038ec59246f8b to your computer and use it in GitHub Desktop.
diff --git a/include/llvm/Analysis/VectorUtils.h b/include/llvm/Analysis/VectorUtils.h
index a73f9fc..6bd11aa 100644
--- a/include/llvm/Analysis/VectorUtils.h
+++ b/include/llvm/Analysis/VectorUtils.h
@@ -115,6 +115,14 @@ computeMinimumValueSizes(ArrayRef<BasicBlock*> Blocks,
const TargetTransformInfo *TTI=nullptr);
/// \returns \p I after propagating metadata from \p VL.
+///
+/// Specifically, let Kinds = [MD_tbaa, MD_alias_scope, MD_noalias, MD_fpmath,
+/// MD_nontemporal]. For K in Kinds, we get the MDNode for K from each of the
+/// elements of VL, compute their "intersection" (i.e., the most generic
+/// metadata value that covers all of the individual values), and set I's
+/// metadata for M equal to the intersection value.
+///
+/// This function always sets a (possibly null) value for each K in Kinds.
Instruction *propagateMetadata(Instruction *I, ArrayRef<Value *> VL);
} // llvm namespace
diff --git a/lib/Analysis/VectorUtils.cpp b/lib/Analysis/VectorUtils.cpp
index 55cc538..e0f968d 100644
--- a/lib/Analysis/VectorUtils.cpp
+++ b/lib/Analysis/VectorUtils.cpp
@@ -454,14 +454,12 @@ Instruction *llvm::propagateMetadata(Instruction *Inst, ArrayRef<Value *> VL) {
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 J = 1, E = VL.size(); MD && J != E; ++J) {
- const Instruction *IJ = cast<Instruction>(VL[J]);
- MDNode *IMD = IJ->getMetadata(Kind);
-
+ 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 I = 1, N = VL.size(); I != N; ++I) {
+ MDNode *IMD = cast<Instruction>(VL[I])->getMetadata(Kind);
switch (Kind) {
case LLVMContext::MD_tbaa:
MD = MDNode::getMostGenericTBAA(MD, IMD);
@@ -479,11 +477,9 @@ Instruction *llvm::propagateMetadata(Instruction *Inst, ArrayRef<Value *> VL) {
MD = MDNode::intersect(MD, IMD);
break;
default:
- MD = nullptr; // Remove unknown metadata.
- break;
+ assert(false && "Unreachable");
}
}
-
Inst->setMetadata(Kind, MD);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment