From: Dmitry Preobrazhensky Date: Fri, 11 Oct 2019 14:05:09 +0000 (+0000) Subject: [AMDGPU][MC] Corrected parsing of optional operands X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=702b2af051c1ef94b20085d92404b2fcd491a26e;p=llvm [AMDGPU][MC] Corrected parsing of optional operands See https://bugs.llvm.org/show_bug.cgi?id=43486 Reviewers: artem.tamazov, arsenm Differential Revision: https://reviews.llvm.org/D68350 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@374553 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp b/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp index 94d1d350dfd..9ef8b309ee2 100644 --- a/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp +++ b/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp @@ -6074,8 +6074,6 @@ static const OptionalOperand AMDGPUOptionalOperandTable[] = { }; OperandMatchResultTy AMDGPUAsmParser::parseOptionalOperand(OperandVector &Operands) { - unsigned size = Operands.size(); - assert(size > 0); OperandMatchResultTy res = parseOptionalOpr(Operands); @@ -6090,17 +6088,13 @@ OperandMatchResultTy AMDGPUAsmParser::parseOptionalOperand(OperandVector &Operan // to make sure autogenerated parser of custom operands never hit hardcoded // mandatory operands. - if (size == 1 || ((AMDGPUOperand &)*Operands[size - 1]).isRegKind()) { - - // We have parsed the first optional operand. - // Parse as many operands as necessary to skip all mandatory operands. + for (unsigned i = 0; i < MAX_OPR_LOOKAHEAD; ++i) { + if (res != MatchOperand_Success || + isToken(AsmToken::EndOfStatement)) + break; - for (unsigned i = 0; i < MAX_OPR_LOOKAHEAD; ++i) { - if (res != MatchOperand_Success || - getLexer().is(AsmToken::EndOfStatement)) break; - if (getLexer().is(AsmToken::Comma)) Parser.Lex(); - res = parseOptionalOpr(Operands); - } + trySkipToken(AsmToken::Comma); + res = parseOptionalOpr(Operands); } return res; diff --git a/test/MC/AMDGPU/flat-global.s b/test/MC/AMDGPU/flat-global.s index 0c9d4d0d77c..83b0c4c29b6 100644 --- a/test/MC/AMDGPU/flat-global.s +++ b/test/MC/AMDGPU/flat-global.s @@ -526,3 +526,8 @@ global_store_short_d16_hi v[3:4], v1, off // GFX10: encoding: [0x00,0x80,0x6c,0xdc,0x03,0x01,0x7d,0x00] // GFX9: global_store_short_d16_hi v[3:4], v1, off ; encoding: [0x00,0x80,0x6c,0xdc,0x03,0x01,0x7f,0x00] // VI-ERR: instruction not supported on this GPU + +global_atomic_add v0, v[1:2], v2, off glc slc +// GFX10: global_atomic_add v0, v[1:2], v2, off glc slc ; encoding: [0x00,0x80,0xcb,0xdc,0x01,0x02,0x7d,0x00] +// GFX9: global_atomic_add v0, v[1:2], v2, off glc slc ; encoding: [0x00,0x80,0x0b,0xdd,0x01,0x02,0x7f,0x00] +// VI-ERR: error: invalid operand for instruction