[llvm-branch-commits] [llvm] 88e5893 - [RISCV] When parsing vsetvli in the assembler, use StringRef::getAsInteger instead of APInt's string constructor
Craig Topper via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Dec 8 11:31:33 PST 2020
Author: Craig Topper
Date: 2020-12-08T11:25:39-08:00
New Revision: 88e58939dcea54d59a77277d420a014dc90b06e7
URL: https://github.com/llvm/llvm-project/commit/88e58939dcea54d59a77277d420a014dc90b06e7
DIFF: https://github.com/llvm/llvm-project/commit/88e58939dcea54d59a77277d420a014dc90b06e7.diff
LOG: [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
Added:
Modified:
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
llvm/test/MC/RISCV/rvv/invalid.s
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
index d5692af9e681..9245e09a6163 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -867,12 +867,11 @@ struct RISCVOperand : public MCParsedAsmOperand {
}
static std::unique_ptr<RISCVOperand>
- 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<RISCVOperand>(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<VSEW>(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 040d7455dfb4..cadafcb35468 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
More information about the llvm-branch-commits
mailing list