diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp --- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp +++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp @@ -1566,10 +1566,26 @@ OperandMatchResultTy RISCVAsmParser::parseVTypeI(OperandVector &Operands) { SMLoc S = getLoc(); - if (getLexer().isNot(AsmToken::Identifier)) + if (getLexer().isNot(AsmToken::Identifier) && + getLexer().isNot(AsmToken::Integer)) return MatchOperand_NoMatch; SmallVector VTypeIElements; + + // Support non-canonical syntax: + // vsetivli rd, uimm, 0xabc or vsetvli rd, rs1, 0xabc + if (getLexer().is(AsmToken::Integer)) { + int64_t Val = getLexer().getTok().getIntVal(); + VTypeIElements.push_back(getLexer().getTok()); + getLexer().Lex(); + // illegal values: vlmul[2:0]=4, vsew[2:0]=0b1xx, non-zero bits 8/9/10. + if (RISCVVType::getVLMUL(Val) == RISCVII::VLMUL::LMUL_RESERVED || + RISCVVType::getSEW(Val) > 64 || (Val >> 8) != 0) + goto MatchFail; + Operands.push_back(RISCVOperand::createVType(Val, S, isRV64())); + return MatchOperand_Success; + } + // Put all the tokens for vtypei operand into VTypeIElements vector. while (getLexer().isNot(AsmToken::EndOfStatement)) { VTypeIElements.push_back(getLexer().getTok()); diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoV.td b/llvm/lib/Target/RISCV/RISCVInstrInfoV.td --- a/llvm/lib/Target/RISCV/RISCVInstrInfoV.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoV.td @@ -25,12 +25,15 @@ let DiagnosticType = "InvalidVTypeI"; } -def VTypeIOp : Operand { +class VTypeIOp : Operand { let ParserMatchClass = VTypeIAsmOperand; let PrintMethod = "printVTypeI"; - let DecoderMethod = "decodeUImmOperand<11>"; + let DecoderMethod = "decodeUImmOperand<"#TypeDigits#">"; } +def VTypeIOp10 : VTypeIOp<10>; +def VTypeIOp11 : VTypeIOp<11>; + def VMaskAsmOperand : AsmOperandClass { let Name = "RVVMaskRegOpOperand"; let RenderMethod = "addRegOperands"; @@ -800,10 +803,10 @@ let Predicates = [HasStdExtV] in { let hasSideEffects = 1, mayLoad = 0, mayStore = 0 in { -def VSETVLI : RVInstSetVLi<(outs GPR:$rd), (ins GPR:$rs1, VTypeIOp:$vtypei), +def VSETVLI : RVInstSetVLi<(outs GPR:$rd), (ins GPR:$rs1, VTypeIOp11:$vtypei), "vsetvli", "$rd, $rs1, $vtypei">; -def VSETIVLI : RVInstSetiVLi<(outs GPR:$rd), (ins uimm5:$uimm, VTypeIOp:$vtypei), +def VSETIVLI : RVInstSetiVLi<(outs GPR:$rd), (ins uimm5:$uimm, VTypeIOp10:$vtypei), "vsetivli", "$rd, $uimm, $vtypei">; def VSETVL : RVInstSetVL<(outs GPR:$rd), (ins GPR:$rs1, GPR:$rs2), diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td b/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td --- a/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td @@ -3517,9 +3517,9 @@ // the when we aren't using one of the special X0 encodings. Otherwise it could // be accidentally be made X0 by MachineIR optimizations. To satisfy the // verifier, we also need a GPRX0 instruction for the special encodings. -def PseudoVSETVLI : Pseudo<(outs GPR:$rd), (ins GPRNoX0:$rs1, VTypeIOp:$vtypei), []>; -def PseudoVSETVLIX0 : Pseudo<(outs GPR:$rd), (ins GPRX0:$rs1, VTypeIOp:$vtypei), []>; -def PseudoVSETIVLI : Pseudo<(outs GPR:$rd), (ins uimm5:$rs1, VTypeIOp:$vtypei), []>; +def PseudoVSETVLI : Pseudo<(outs GPR:$rd), (ins GPRNoX0:$rs1, VTypeIOp11:$vtypei), []>; +def PseudoVSETVLIX0 : Pseudo<(outs GPR:$rd), (ins GPRX0:$rs1, VTypeIOp11:$vtypei), []>; +def PseudoVSETIVLI : Pseudo<(outs GPR:$rd), (ins uimm5:$rs1, VTypeIOp10:$vtypei), []>; } //===----------------------------------------------------------------------===// diff --git a/llvm/test/MC/RISCV/rvv/invalid.s b/llvm/test/MC/RISCV/rvv/invalid.s --- a/llvm/test/MC/RISCV/rvv/invalid.s +++ b/llvm/test/MC/RISCV/rvv/invalid.s @@ -10,6 +10,21 @@ vsetivli a2, 5, e31 # 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] +vsetivli a2, 0, 0x4 +# 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] + +vsetivli a2, 0, 0x20 +# 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] + +vsetivli a2, 0, 0x200 +# 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] + +vsetivli a2, 0, 0x224 +# 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] + +vsetivli a2, 0, 548 +# 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, e31 # 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] @@ -64,6 +79,21 @@ vsetvli a2, a0, e8,m1,ta # 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, 0x4 +# 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, 0x20 +# 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, 0x200 +# 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, 0x224 +# 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, 548 +# 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 diff --git a/llvm/test/MC/RISCV/rvv/vsetvl.s b/llvm/test/MC/RISCV/rvv/vsetvl.s --- a/llvm/test/MC/RISCV/rvv/vsetvl.s +++ b/llvm/test/MC/RISCV/rvv/vsetvl.s @@ -8,6 +8,36 @@ # RUN: llvm-mc -triple=riscv64 -filetype=obj --mattr=+experimental-v %s \ # RUN: | llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN +vsetvli a2, a0, 0xd0 +# CHECK-INST: vsetvli a2, a0, e32, m1, ta, ma +# CHECK-ENCODING: [0x57,0x76,0x05,0x0d] +# CHECK-ERROR: instruction requires the following: 'V' (Vector Instructions) +# CHECK-UNKNOWN: 57 76 05 0d + +vsetvli a2, a0, 0xd1 +# CHECK-INST: vsetvli a2, a0, e32, m2, ta, ma +# CHECK-ENCODING: [0x57,0x76,0x15,0x0d] +# CHECK-ERROR: instruction requires the following: 'V' (Vector Instructions) +# CHECK-UNKNOWN: 57 76 15 0d + +vsetvli a2, a0, 0x50 +# CHECK-INST: vsetvli a2, a0, e32, m1, ta, mu +# CHECK-ENCODING: [0x57,0x76,0x05,0x05] +# CHECK-ERROR: instruction requires the following: 'V' (Vector Instructions) +# CHECK-UNKNOWN: 57 76 05 05 + +vsetvli a2, a0, 0x90 +# CHECK-INST: vsetvli a2, a0, e32, m1, tu, ma +# CHECK-ENCODING: [0x57,0x76,0x05,0x09] +# CHECK-ERROR: instruction requires the following: 'V' (Vector Instructions) +# CHECK-UNKNOWN: 57 76 05 09 + +vsetvli a2, a0, 144 +# CHECK-INST: vsetvli a2, a0, e32, m1, tu, ma +# CHECK-ENCODING: [0x57,0x76,0x05,0x09] +# CHECK-ERROR: instruction requires the following: 'V' (Vector Instructions) +# CHECK-UNKNOWN: 57 76 05 09 + vsetvli a2, a0, e32, m1, ta, ma # CHECK-INST: vsetvli a2, a0, e32, m1, ta, ma # CHECK-ENCODING: [0x57,0x76,0x05,0x0d] @@ -80,6 +110,24 @@ # CHECK-ERROR: instruction requires the following: 'V' (Vector Instructions) # CHECK-UNKNOWN: 57 76 b5 80 +vsetivli a2, 0, 0xd0 +# CHECK-INST: vsetivli a2, 0, e32, m1, ta, ma +# CHECK-ENCODING: [0x57,0x76,0x00,0xcd] +# CHECK-ERROR: instruction requires the following: 'V' (Vector Instructions) +# CHECK-UNKNOWN: 57 76 00 cd + +vsetivli a2, 15, 0xd0 +# CHECK-INST: vsetivli a2, 15, e32, m1, ta, ma +# CHECK-ENCODING: [0x57,0xf6,0x07,0xcd] +# CHECK-ERROR: instruction requires the following: 'V' (Vector Instructions) +# CHECK-UNKNOWN: 57 f6 07 cd + +vsetivli a2, 15, 208 +# CHECK-INST: vsetivli a2, 15, e32, m1, ta, ma +# CHECK-ENCODING: [0x57,0xf6,0x07,0xcd] +# CHECK-ERROR: instruction requires the following: 'V' (Vector Instructions) +# CHECK-UNKNOWN: 57 f6 07 cd + vsetivli a2, 0, e32, m1, ta, ma # CHECK-INST: vsetivli a2, 0, e32, m1, ta, ma # CHECK-ENCODING: [0x57,0x76,0x00,0xcd]