diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp --- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -2368,10 +2368,15 @@ } else { MIB.addFPImm(cast(Arg.value())); } - } else if (auto MD = dyn_cast(Arg.value())) { - auto *MDN = dyn_cast(MD->getMetadata()); - if (!MDN) // This was probably an MDString. - return false; + } else if (auto *MDVal = dyn_cast(Arg.value())) { + auto *MD = MDVal->getMetadata(); + auto *MDN = dyn_cast(MD); + if (!MDN) { + if (auto *ConstMD = dyn_cast(MD)) + MDN = MDNode::get(MF->getFunction().getContext(), ConstMD); + else // This was probably an MDString. + return false; + } MIB.addMetadata(MDN); } else { ArrayRef VRegs = getOrCreateVRegs(*Arg.value());