Skip to content

Commit 959c08d

Browse files
Add more tests and fix craigs comments about parser
1 parent f7a5dec commit 959c08d

File tree

2 files changed

+124
-16
lines changed

2 files changed

+124
-16
lines changed

llvm/lib/CodeGen/MIRParser/MIParser.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,15 +1950,16 @@ bool MIParser::parseLowLevelType(StringRef::iterator Loc, LLT &Ty) {
19501950
"or <vscale x M x pA> for GlobalISel type");
19511951
lex();
19521952

1953-
bool HasVScale = Token.stringValue() == "vscale";
1953+
bool HasVScale =
1954+
Token.is(MIToken::Identifier) && Token.stringValue() == "vscale";
19541955
if (HasVScale) {
19551956
lex();
1956-
if (Token.stringValue() != "x")
1957+
if (Token.isNot(MIToken::Identifier) || Token.stringValue() != "x")
19571958
return error("expected <vscale x M x sN> or <vscale x M x pA>");
19581959
lex();
19591960
}
19601961

1961-
auto GetError = [&](bool HasVScale, StringRef::iterator Loc) {
1962+
auto GetError = [this, &HasVScale, Loc]() {
19621963
if (HasVScale)
19631964
return error(
19641965
Loc, "expected <vscale x M x sN> or <vscale M x pA> for vector type");
@@ -1967,19 +1968,19 @@ bool MIParser::parseLowLevelType(StringRef::iterator Loc, LLT &Ty) {
19671968
};
19681969

19691970
if (Token.isNot(MIToken::IntegerLiteral))
1970-
return GetError(HasVScale, Loc);
1971+
return GetError();
19711972
uint64_t NumElements = Token.integerValue().getZExtValue();
19721973
if (!verifyVectorElementCount(NumElements))
19731974
return error("invalid number of vector elements");
19741975

19751976
lex();
19761977

19771978
if (Token.isNot(MIToken::Identifier) || Token.stringValue() != "x")
1978-
return GetError(HasVScale, Loc);
1979+
return GetError();
19791980
lex();
19801981

19811982
if (Token.range().front() != 's' && Token.range().front() != 'p')
1982-
return GetError(HasVScale, Loc);
1983+
return GetError();
19831984

19841985
StringRef SizeStr = Token.range().drop_front();
19851986
if (SizeStr.size() == 0 || !llvm::all_of(SizeStr, isdigit))
@@ -1998,18 +1999,15 @@ bool MIParser::parseLowLevelType(StringRef::iterator Loc, LLT &Ty) {
19981999

19992000
Ty = LLT::pointer(AS, DL.getPointerSizeInBits(AS));
20002001
} else
2001-
return GetError(HasVScale, Loc);
2002+
return GetError();
20022003
lex();
20032004

20042005
if (Token.isNot(MIToken::greater))
2005-
return GetError(HasVScale, Loc);
2006+
return GetError();
20062007

20072008
lex();
20082009

2009-
if (HasVScale)
2010-
Ty = LLT::scalable_vector(NumElements, Ty);
2011-
else
2012-
Ty = LLT::fixed_vector(NumElements, Ty);
2010+
Ty = LLT::vector(ElementCount::get(NumElements, HasVScale), Ty);
20132011
return false;
20142012
}
20152013

Lines changed: 114 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,133 @@
11
# RUN: llc -run-pass=none -o - %s | FileCheck %s
22

33
---
4-
name: scalable_vector_type_s
4+
name: test_nxv1s8
55
body: |
66
bb.0:
7-
; CHECK-LABEL: name: scalable_vector_type_s
7+
; CHECK-LABEL: name: test_nxv1s8
88
; CHECK: [[DEF:%[0-9]+]]:_(<vscale x 1 x s8>) = IMPLICIT_DEF
99
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<vscale x 1 x s8>) = COPY [[DEF]](<vscale x 1 x s8>)
1010
%0:_(<vscale x 1 x s8>) = IMPLICIT_DEF
1111
%1:_(<vscale x 1 x s8>) = COPY %0
1212
...
1313

1414
---
15-
name: scalable_vector_type_p
15+
name: test_nxv1s16
1616
body: |
1717
bb.0:
18-
; CHECK-LABEL: name: scalable_vector_type_p
18+
; CHECK-LABEL: name: test_nxv1s16
19+
; CHECK: [[DEF:%[0-9]+]]:_(<vscale x 1 x s16>) = IMPLICIT_DEF
20+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<vscale x 1 x s16>) = COPY [[DEF]](<vscale x 1 x s16>)
21+
%0:_(<vscale x 1 x s16>) = IMPLICIT_DEF
22+
%1:_(<vscale x 1 x s16>) = COPY %0
23+
...
24+
25+
---
26+
name: test_nxv1s32
27+
body: |
28+
bb.0:
29+
; CHECK-LABEL: name: test_nxv1s32
30+
; CHECK: [[DEF:%[0-9]+]]:_(<vscale x 1 x s32>) = IMPLICIT_DEF
31+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<vscale x 1 x s32>) = COPY [[DEF]](<vscale x 1 x s32>)
32+
%0:_(<vscale x 1 x s32>) = IMPLICIT_DEF
33+
%1:_(<vscale x 1 x s32>) = COPY %0
34+
...
35+
36+
---
37+
name: test_nxv1s64
38+
body: |
39+
bb.0:
40+
; CHECK-LABEL: name: test_nxv1s64
41+
; CHECK: [[DEF:%[0-9]+]]:_(<vscale x 1 x s64>) = IMPLICIT_DEF
42+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<vscale x 1 x s64>) = COPY [[DEF]](<vscale x 1 x s64>)
43+
%0:_(<vscale x 1 x s64>) = IMPLICIT_DEF
44+
%1:_(<vscale x 1 x s64>) = COPY %0
45+
...
46+
47+
---
48+
name: test_nxv4s8
49+
body: |
50+
bb.0:
51+
; CHECK-LABEL: name: test_nxv4s8
52+
; CHECK: [[DEF:%[0-9]+]]:_(<vscale x 4 x s8>) = IMPLICIT_DEF
53+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<vscale x 4 x s8>) = COPY [[DEF]](<vscale x 4 x s8>)
54+
%0:_(<vscale x 4 x s8>) = IMPLICIT_DEF
55+
%1:_(<vscale x 4 x s8>) = COPY %0
56+
...
57+
58+
---
59+
name: test_nxv4s16
60+
body: |
61+
bb.0:
62+
; CHECK-LABEL: name: test_nxv4s16
63+
; CHECK: [[DEF:%[0-9]+]]:_(<vscale x 4 x s16>) = IMPLICIT_DEF
64+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<vscale x 4 x s16>) = COPY [[DEF]](<vscale x 4 x s16>)
65+
%0:_(<vscale x 4 x s16>) = IMPLICIT_DEF
66+
%1:_(<vscale x 4 x s16>) = COPY %0
67+
...
68+
69+
---
70+
name: test_nxv4s32
71+
body: |
72+
bb.0:
73+
; CHECK-LABEL: name: test_nxv4s32
74+
; CHECK: [[DEF:%[0-9]+]]:_(<vscale x 4 x s32>) = IMPLICIT_DEF
75+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<vscale x 4 x s32>) = COPY [[DEF]](<vscale x 4 x s32>)
76+
%0:_(<vscale x 4 x s32>) = IMPLICIT_DEF
77+
%1:_(<vscale x 4 x s32>) = COPY %0
78+
...
79+
80+
---
81+
name: test_nxv4s64
82+
body: |
83+
bb.0:
84+
; CHECK-LABEL: name: test_nxv4s64
85+
; CHECK: [[DEF:%[0-9]+]]:_(<vscale x 4 x s64>) = IMPLICIT_DEF
86+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<vscale x 4 x s64>) = COPY [[DEF]](<vscale x 4 x s64>)
87+
%0:_(<vscale x 4 x s64>) = IMPLICIT_DEF
88+
%1:_(<vscale x 4 x s64>) = COPY %0
89+
...
90+
91+
---
92+
name: test_nxv1p0
93+
body: |
94+
bb.0:
95+
; CHECK-LABEL: name: test_nxv1p0
1996
; CHECK: [[DEF:%[0-9]+]]:_(<vscale x 1 x p0>) = IMPLICIT_DEF
2097
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<vscale x 1 x p0>) = COPY [[DEF]](<vscale x 1 x p0>)
2198
%0:_(<vscale x 1 x p0>) = IMPLICIT_DEF
2299
%1:_(<vscale x 1 x p0>) = COPY %0
23100
...
101+
102+
---
103+
name: test_nxv1sp1
104+
body: |
105+
bb.0:
106+
; CHECK-LABEL: name: test_nxv1sp1
107+
; CHECK: [[DEF:%[0-9]+]]:_(<vscale x 1 x p0>) = IMPLICIT_DEF
108+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<vscale x 1 x p0>) = COPY [[DEF]](<vscale x 1 x p0>)
109+
%0:_(<vscale x 1 x p0>) = IMPLICIT_DEF
110+
%1:_(<vscale x 1 x p0>) = COPY %0
111+
...
112+
113+
---
114+
name: test_nxv4p0
115+
body: |
116+
bb.0:
117+
; CHECK-LABEL: name: test_nxv4p0
118+
; CHECK: [[DEF:%[0-9]+]]:_(<vscale x 4 x p0>) = IMPLICIT_DEF
119+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<vscale x 4 x p0>) = COPY [[DEF]](<vscale x 4 x p0>)
120+
%0:_(<vscale x 4 x p0>) = IMPLICIT_DEF
121+
%1:_(<vscale x 4 x p0>) = COPY %0
122+
...
123+
124+
---
125+
name: test_nxv4p1
126+
body: |
127+
bb.0:
128+
; CHECK-LABEL: name: test_nxv4p1
129+
; CHECK: [[DEF:%[0-9]+]]:_(<vscale x 4 x p1>) = IMPLICIT_DEF
130+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(<vscale x 4 x p1>) = COPY [[DEF]](<vscale x 4 x p1>)
131+
%0:_(<vscale x 4 x p1>) = IMPLICIT_DEF
132+
%1:_(<vscale x 4 x p1>) = COPY %0
133+
...

0 commit comments

Comments
 (0)