Allow empty value list in propagateMetadata(Inst, ArrayOf...)
authorKrzysztof Parzyszek <kparzysz@quicinc.com>
Fri, 7 May 2021 17:52:20 +0000 (12:52 -0500)
committerKrzysztof Parzyszek <kparzysz@quicinc.com>
Fri, 7 May 2021 18:20:50 +0000 (13:20 -0500)
This will allow writing
  propagateMetadata(Inst, collectInterestingValues(...))
without concern about empty lists. In case of an empty list,
Inst is returned without any changes.

llvm/lib/Analysis/VectorUtils.cpp

index aeec439..f7c3929 100644 (file)
@@ -708,6 +708,8 @@ MDNode *llvm::intersectAccessGroups(const Instruction *Inst1,
 
 /// \returns \p I after propagating metadata from \p VL.
 Instruction *llvm::propagateMetadata(Instruction *Inst, ArrayRef<Value *> VL) {
+  if (VL.empty())
+    return Inst;
   Instruction *I0 = cast<Instruction>(VL[0]);
   SmallVector<std::pair<unsigned, MDNode *>, 4> Metadata;
   I0->getAllMetadataOtherThanDebugLoc(Metadata);