From 88e58939dcea54d59a77277d420a014dc90b06e7 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Tue, 8 Dec 2020 10:30:06 -0800 Subject: [PATCH] [RISCV] When parsing vsetvli in the assembler, use StringRef::getAsInteger instead of APInt's string constructor APInt's string constructor asserts on error. Since this is the parser and we don't yet know if the string is a valid integer we shouldn't use that. Instead use StringRef::getAsInteger which returns a bool to indicate success or failure. Since we no longer need APInt, use 'unsigned' instead. Differential Revision: https://reviews.llvm.org/D92801 --- llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp | 15 +++++++++------ llvm/test/MC/RISCV/rvv/invalid.s | 6 ++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp index d5692af9e68..9245e09a616 100644 --- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp +++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp @@ -867,12 +867,11 @@ public: } static std::unique_ptr - createVType(APInt Sew, APInt Lmul, bool Fractional, bool TailAgnostic, + createVType(unsigned Sew, unsigned Lmul, bool Fractional, bool TailAgnostic, bool MaskedoffAgnostic, SMLoc S, bool IsRV64) { auto Op = std::make_unique(KindTy::VType); - Sew.ashrInPlace(3); - unsigned SewLog2 = Sew.logBase2(); - unsigned LmulLog2 = Lmul.logBase2(); + unsigned SewLog2 = Log2_32(Sew / 8); + unsigned LmulLog2 = Log2_32(Lmul); Op->VType.Sew = static_cast(SewLog2); if (Fractional) { unsigned Flmul = 8 - LmulLog2; @@ -1598,7 +1597,9 @@ OperandMatchResultTy RISCVAsmParser::parseVTypeI(OperandVector &Operands) { StringRef Name = getLexer().getTok().getIdentifier(); if (!Name.consume_front("e")) return MatchOperand_NoMatch; - APInt Sew(16, Name, 10); + unsigned Sew; + if (Name.getAsInteger(10, Sew)) + return MatchOperand_NoMatch; if (Sew != 8 && Sew != 16 && Sew != 32 && Sew != 64 && Sew != 128 && Sew != 256 && Sew != 512 && Sew != 1024) return MatchOperand_NoMatch; @@ -1616,7 +1617,9 @@ OperandMatchResultTy RISCVAsmParser::parseVTypeI(OperandVector &Operands) { if (Name.consume_front("f")) { Fractional = true; } - APInt Lmul(16, Name, 10); + unsigned Lmul; + if (Name.getAsInteger(10, Lmul)) + return MatchOperand_NoMatch; if (Lmul != 1 && Lmul != 2 && Lmul != 4 && Lmul != 8) return MatchOperand_NoMatch; getLexer().Lex(); diff --git a/llvm/test/MC/RISCV/rvv/invalid.s b/llvm/test/MC/RISCV/rvv/invalid.s index 040d7455dfb..cadafcb3546 100644 --- a/llvm/test/MC/RISCV/rvv/invalid.s +++ b/llvm/test/MC/RISCV/rvv/invalid.s @@ -31,6 +31,12 @@ vsetvli a2, a0, e8,m1,ma vsetvli a2, a0, e8,m1,mu # CHECK-ERROR: operand must be e[8|16|32|64|128|256|512|1024],m[1|2|4|8|f2|f4|f8],[ta|tu],[ma|mu] +vsetvli a2, a0, e8x,m1,tu,mu +# CHECK-ERROR: operand must be e[8|16|32|64|128|256|512|1024],m[1|2|4|8|f2|f4|f8],[ta|tu],[ma|mu] + +vsetvli a2, a0, e8,m1z,tu,mu +# CHECK-ERROR: operand must be e[8|16|32|64|128|256|512|1024],m[1|2|4|8|f2|f4|f8],[ta|tu],[ma|mu] + vadd.vv v1, v3, v2, v4.t # CHECK-ERROR: operand must be v0.t -- 2.11.0