diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index f41907f035125..bfd25c98a9446 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -3201,9 +3201,22 @@ bool LLParser::parseOptionalOperandBundles( return true; Type *Ty = nullptr; - Value *Input = nullptr; - if (parseType(Ty) || parseValue(Ty, Input, PFS)) + if (parseType(Ty)) return true; + + Value *Input = nullptr; + // FIXME: Metadata operand bundle value is garbage when LLVM IR is + // compiled to bitcode, then disassembled back to LLVM IR. + // See [PR#89649](https://github.com/llvm/llvm-project/pull/89649) + // for the reproducers, and + // https://github.com/llvm/llvm-project/issues/50608 for the bug report. + if (Ty->isMetadataTy()) { + if (parseMetadataAsValue(Input, PFS)) + return true; + } else { + if (parseValue(Ty, Input, PFS)) + return true; + } Inputs.push_back(Input); } diff --git a/llvm/test/Bitcode/2021-07-22-Parse-Metadata-Operand-Bundles.ll b/llvm/test/Bitcode/2021-07-22-Parse-Metadata-Operand-Bundles.ll new file mode 100644 index 0000000000000..35c6131bbad60 --- /dev/null +++ b/llvm/test/Bitcode/2021-07-22-Parse-Metadata-Operand-Bundles.ll @@ -0,0 +1,9 @@ +; This test ensures that we parse metadata operand bundle values. +; RUN: llvm-as < %s + +declare void @callee() + +define void @call_with_operand_bundle() { + call void @callee() [ "op_type"(metadata !"metadata_string") ] + ret void +}