Skip to content

Commit 876c620

Browse files
authored
[RISCV][MC] Warn if SEW/LMUL may not be compatible
According to RVV spec: > In general, the requirement is to support LMUL ≥ SEWMIN/ELEN, > where SEWMIN is the narrowest supported SEW value and ELEN is > the widest supported SEW value. > > For a given supported fractional LMUL setting, implementations > must support SEW settings between SEWMIN and LMUL * ELEN, inclusive. We print a warning if these requirements are not met. Reviewers: kito-cheng, asb, frasercrmck, jrtc27, michaelmaitland, lukel97 Reviewed By: lukel97 Pull Request: #94313
1 parent bfa8150 commit 876c620

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,6 +2155,16 @@ bool RISCVAsmParser::parseVTypeToken(const AsmToken &Tok, VTypeState &State,
21552155
break;
21562156
if (!RISCVVType::isValidLMUL(Lmul, Fractional))
21572157
break;
2158+
2159+
if (Fractional) {
2160+
unsigned ELEN = STI->hasFeature(RISCV::FeatureStdExtZve64x) ? 64 : 32;
2161+
unsigned MinLMUL = ELEN / 8;
2162+
if (Lmul > MinLMUL)
2163+
Warning(Tok.getLoc(),
2164+
"use of vtype encodings with LMUL < SEWMIN/ELEN == mf" +
2165+
Twine(MinLMUL) + " is reserved");
2166+
}
2167+
21582168
State = VTypeState_TailPolicy;
21592169
return false;
21602170
}
@@ -2194,6 +2204,7 @@ ParseStatus RISCVAsmParser::parseVTypeI(OperandVector &Operands) {
21942204
bool MaskAgnostic = false;
21952205

21962206
VTypeState State = VTypeState_SEW;
2207+
SMLoc SEWLoc = S;
21972208

21982209
if (parseVTypeToken(getTok(), State, Sew, Lmul, Fractional, TailAgnostic,
21992210
MaskAgnostic))
@@ -2211,6 +2222,16 @@ ParseStatus RISCVAsmParser::parseVTypeI(OperandVector &Operands) {
22112222

22122223
if (getLexer().is(AsmToken::EndOfStatement) && State == VTypeState_Done) {
22132224
RISCVII::VLMUL VLMUL = RISCVVType::encodeLMUL(Lmul, Fractional);
2225+
if (Fractional) {
2226+
unsigned ELEN = STI->hasFeature(RISCV::FeatureStdExtZve64x) ? 64 : 32;
2227+
unsigned MaxSEW = ELEN / Lmul;
2228+
// If MaxSEW < 8, we should have printed warning about reserved LMUL.
2229+
if (MaxSEW >= 8 && Sew > MaxSEW)
2230+
Warning(SEWLoc,
2231+
"use of vtype encodings with SEW > " + Twine(MaxSEW) +
2232+
" and LMUL == mf" + Twine(Lmul) +
2233+
" may not be compatible with all RVV implementations");
2234+
}
22142235

22152236
unsigned VTypeI =
22162237
RISCVVType::encodeVTYPE(VLMUL, Sew, TailAgnostic, MaskAgnostic);

llvm/test/MC/RISCV/rvv/vsetvl.s

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# RUN: llvm-mc -triple=riscv64 -show-encoding --mattr=+v %s \
22
# RUN: | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
3+
# RUN: llvm-mc -triple=riscv64 -show-encoding --mattr=+zve32x %s 2>&1 \
4+
# RUN: | FileCheck %s --check-prefix=CHECK-ZVE32X
35
# RUN: not llvm-mc -triple=riscv64 -show-encoding %s 2>&1 \
46
# RUN: | FileCheck %s --check-prefix=CHECK-ERROR
57
# RUN: llvm-mc -triple=riscv64 -filetype=obj --mattr=+v %s \
@@ -71,18 +73,21 @@ vsetvli a2, a0, e32, m8, ta, ma
7173

7274
vsetvli a2, a0, e32, mf2, ta, ma
7375
# CHECK-INST: vsetvli a2, a0, e32, mf2, ta, ma
76+
# CHECK-ZVE32X: :[[#@LINE-2]]:17: warning: use of vtype encodings with SEW > 16 and LMUL == mf2 may not be compatible with all RVV implementations{{$}}
7477
# CHECK-ENCODING: [0x57,0x76,0x75,0x0d]
7578
# CHECK-ERROR: instruction requires the following: 'V' (Vector Extension for Application Processors), 'Zve32x' (Vector Extensions for Embedded Processors){{$}}
7679
# CHECK-UNKNOWN: 0d757657 <unknown>
7780

7881
vsetvli a2, a0, e32, mf4, ta, ma
7982
# CHECK-INST: vsetvli a2, a0, e32, mf4, ta, ma
83+
# CHECK-ZVE32X: :[[#@LINE-2]]:17: warning: use of vtype encodings with SEW > 8 and LMUL == mf4 may not be compatible with all RVV implementations{{$}}
8084
# CHECK-ENCODING: [0x57,0x76,0x65,0x0d]
8185
# CHECK-ERROR: instruction requires the following: 'V' (Vector Extension for Application Processors), 'Zve32x' (Vector Extensions for Embedded Processors){{$}}
8286
# CHECK-UNKNOWN: 0d657657 <unknown>
8387

8488
vsetvli a2, a0, e32, mf8, ta, ma
8589
# CHECK-INST: vsetvli a2, a0, e32, mf8, ta, ma
90+
# CHECK-ZVE32X: :[[#@LINE-2]]:22: warning: use of vtype encodings with LMUL < SEWMIN/ELEN == mf4 is reserved{{$}}
8691
# CHECK-ENCODING: [0x57,0x76,0x55,0x0d]
8792
# CHECK-ERROR: instruction requires the following: 'V' (Vector Extension for Application Processors), 'Zve32x' (Vector Extensions for Embedded Processors){{$}}
8893
# CHECK-UNKNOWN: 0d557657 <unknown>

0 commit comments

Comments
 (0)