Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 971d988

Browse files
committed
[AArch64][SVE] Asm: PTRUE and PTRUES instructions
Summary: These instructions initialize a predicate vector from a pattern/immediate. Reviewers: fhahn, rengolin, evandro, mcrosier, t.p.northover, samparker, olista01 Reviewed By: samparker Subscribers: aemerson, javed.absar, tschuett, kristof.beyls, llvm-commits Differential Revision: https://reviews.llvm.org/D41819 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@323124 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 95a5df8 commit 971d988

File tree

6 files changed

+652
-2
lines changed

6 files changed

+652
-2
lines changed

lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ class AArch64AsmParser : public MCTargetAsmParser {
140140
template <bool ParseSuffix>
141141
OperandMatchResultTy tryParseSVEDataVector(OperandVector &Operands);
142142
OperandMatchResultTy tryParseSVEPredicateVector(OperandVector &Operands);
143-
LLVM_ATTRIBUTE_UNUSED OperandMatchResultTy
144-
tryParseSVEPattern(OperandVector &Operands);
143+
OperandMatchResultTy tryParseSVEPattern(OperandVector &Operands);
145144

146145
public:
147146
enum AArch64MatchResultTy {
@@ -3665,6 +3664,8 @@ bool AArch64AsmParser::showMatchError(SMLoc Loc, unsigned ErrCode,
36653664
ComputeAvailableFeatures(STI->getFeatureBits()));
36663665
return Error(Loc, "unrecognized instruction mnemonic" + Suggestion);
36673666
}
3667+
case Match_InvalidSVEPattern:
3668+
return Error(Loc, "invalid predicate pattern");
36683669
case Match_InvalidSVEPredicateAnyReg:
36693670
case Match_InvalidSVEPredicateBReg:
36703671
case Match_InvalidSVEPredicateHReg:
@@ -4104,6 +4105,7 @@ bool AArch64AsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
41044105
case Match_InvalidComplexRotationEven:
41054106
case Match_InvalidComplexRotationOdd:
41064107
case Match_InvalidSVEPredicateAnyReg:
4108+
case Match_InvalidSVEPattern:
41074109
case Match_InvalidSVEPredicateBReg:
41084110
case Match_InvalidSVEPredicateHReg:
41094111
case Match_InvalidSVEPredicateSReg:

lib/Target/AArch64/SVEInstrFormats.td

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,68 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14+
def SVEPatternOperand : AsmOperandClass {
15+
let Name = "SVEPattern";
16+
let ParserMethod = "tryParseSVEPattern";
17+
let PredicateMethod = "isSVEPattern";
18+
let RenderMethod = "addImmOperands";
19+
let DiagnosticType = "InvalidSVEPattern";
20+
}
21+
22+
def sve_pred_enum : Operand<i32>, ImmLeaf<i32, [{
23+
return (((uint32_t)Imm) < 32);
24+
}]> {
25+
26+
let PrintMethod = "printSVEPattern";
27+
let ParserMatchClass = SVEPatternOperand;
28+
}
29+
30+
//===----------------------------------------------------------------------===//
31+
// SVE PTrue - These are used extensively throughout the pattern matching so
32+
// it's important we define them first.
33+
//===----------------------------------------------------------------------===//
34+
35+
class sve_int_ptrue<bits<2> sz8_64, bits<3> opc, string asm, PPRRegOp pprty>
36+
: I<(outs pprty:$Pd), (ins sve_pred_enum:$pattern),
37+
asm, "\t$Pd, $pattern",
38+
"",
39+
[]>, Sched<[]> {
40+
bits<4> Pd;
41+
bits<5> pattern;
42+
let Inst{31-24} = 0b00100101;
43+
let Inst{23-22} = sz8_64;
44+
let Inst{21-19} = 0b011;
45+
let Inst{18-17} = opc{2-1};
46+
let Inst{16} = opc{0};
47+
let Inst{15-10} = 0b111000;
48+
let Inst{9-5} = pattern;
49+
let Inst{4} = 0b0;
50+
let Inst{3-0} = Pd;
51+
52+
let Defs = !if(!eq (opc{0}, 1), [NZCV], []);
53+
}
54+
55+
multiclass sve_int_ptrue<bits<3> opc, string asm> {
56+
def _B : sve_int_ptrue<0b00, opc, asm, PPR8>;
57+
def _H : sve_int_ptrue<0b01, opc, asm, PPR16>;
58+
def _S : sve_int_ptrue<0b10, opc, asm, PPR32>;
59+
def _D : sve_int_ptrue<0b11, opc, asm, PPR64>;
60+
61+
def : InstAlias<asm # "\t$Pd",
62+
(!cast<Instruction>(NAME # _B) PPR8:$Pd, 0b11111), 1>;
63+
def : InstAlias<asm # "\t$Pd",
64+
(!cast<Instruction>(NAME # _H) PPR16:$Pd, 0b11111), 1>;
65+
def : InstAlias<asm # "\t$Pd",
66+
(!cast<Instruction>(NAME # _S) PPR32:$Pd, 0b11111), 1>;
67+
def : InstAlias<asm # "\t$Pd",
68+
(!cast<Instruction>(NAME # _D) PPR64:$Pd, 0b11111), 1>;
69+
}
70+
71+
let Predicates = [HasSVE] in {
72+
defm PTRUE : sve_int_ptrue<0b000, "ptrue">;
73+
defm PTRUES : sve_int_ptrue<0b001, "ptrues">;
74+
}
75+
1476
//===----------------------------------------------------------------------===//
1577
// SVE Permute - Cross Lane Group
1678
//===----------------------------------------------------------------------===//
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: not llvm-mc -triple=aarch64 -show-encoding -mattr=+sve 2>&1 < %s| FileCheck %s
2+
3+
// --------------------------------------------------------------------------//
4+
// Invalid pattern name
5+
// --------------------------------------------------------------------------//
6+
7+
ptrue p0.s, vl512
8+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid predicate pattern
9+
// CHECK-NEXT: ptrue p0.s, vl512
10+
// CHECK-NOT: [[@LINE-3]]:{{[0-9]+}}:
11+
12+
ptrue p0.s, vl9
13+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid predicate pattern
14+
// CHECK-NEXT: ptrue p0.s, vl9
15+
// CHECK-NOT: [[@LINE-3]]:{{[0-9]+}}:
16+
17+
// --------------------------------------------------------------------------//
18+
// Invalid immediate range
19+
// --------------------------------------------------------------------------//
20+
21+
ptrue p0.s, #-1
22+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid predicate pattern
23+
// CHECK-NEXT: ptrue p0.s, #-1
24+
// CHECK-NOT: [[@LINE-3]]:{{[0-9]+}}:
25+
26+
ptrue p0.s, #32
27+
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: invalid predicate pattern
28+
// CHECK-NEXT: ptrue p0.s, #32
29+
// CHECK-NOT: [[@LINE-3]]:{{[0-9]+}}:

test/MC/AArch64/SVE/ptrue.s

Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
// RUN: llvm-mc -triple=aarch64 -show-encoding -mattr=+sve < %s \
2+
// RUN: | FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
3+
// RUN: not llvm-mc -triple=aarch64 -show-encoding < %s 2>&1 \
4+
// RUN: | FileCheck %s --check-prefix=CHECK-ERROR
5+
// RUN: llvm-mc -triple=aarch64 -filetype=obj -mattr=+sve < %s \
6+
// RUN: | llvm-objdump -d -mattr=+sve - | FileCheck %s --check-prefix=CHECK-INST
7+
// RUN: llvm-mc -triple=aarch64 -filetype=obj -mattr=+sve < %s \
8+
// RUN: | llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN
9+
10+
// ---------------------------------------------------------------------------//
11+
// Test all predicate sizes for pow2 pattern
12+
// ---------------------------------------------------------------------------//
13+
14+
ptrue p0.b, pow2
15+
// CHECK-INST: ptrue p0.b, pow2
16+
// CHECK-ENCODING: [0x00,0xe0,0x18,0x25]
17+
// CHECK-ERROR: instruction requires: sve
18+
// CHECK-UNKNOWN: 00 e0 18 25 <unknown>
19+
20+
ptrue p0.h, pow2
21+
// CHECK-INST: ptrue p0.h, pow2
22+
// CHECK-ENCODING: [0x00,0xe0,0x58,0x25]
23+
// CHECK-ERROR: instruction requires: sve
24+
// CHECK-UNKNOWN: 00 e0 58 25 <unknown>
25+
26+
ptrue p0.s, pow2
27+
// CHECK-INST: ptrue p0.s, pow2
28+
// CHECK-ENCODING: [0x00,0xe0,0x98,0x25]
29+
// CHECK-ERROR: instruction requires: sve
30+
// CHECK-UNKNOWN: 00 e0 98 25 <unknown>
31+
32+
ptrue p0.d, pow2
33+
// CHECK-INST: ptrue p0.d, pow2
34+
// CHECK-ENCODING: [0x00,0xe0,0xd8,0x25]
35+
// CHECK-ERROR: instruction requires: sve
36+
// CHECK-UNKNOWN: 00 e0 d8 25 <unknown>
37+
38+
// ---------------------------------------------------------------------------//
39+
// Test all predicate sizes without explicit pattern
40+
// ---------------------------------------------------------------------------//
41+
42+
ptrue p15.b
43+
// CHECK-INST: ptrue p15.b
44+
// CHECK-ENCODING: [0xef,0xe3,0x18,0x25]
45+
// CHECK-ERROR: instruction requires: sve
46+
// CHECK-UNKNOWN: ef e3 18 25 <unknown>
47+
48+
ptrue p15.h
49+
// CHECK-INST: ptrue p15.h
50+
// CHECK-ENCODING: [0xef,0xe3,0x58,0x25]
51+
// CHECK-ERROR: instruction requires: sve
52+
// CHECK-UNKNOWN: ef e3 58 25 <unknown>
53+
54+
ptrue p15.s
55+
// CHECK-INST: ptrue p15.s
56+
// CHECK-ENCODING: [0xef,0xe3,0x98,0x25]
57+
// CHECK-ERROR: instruction requires: sve
58+
// CHECK-UNKNOWN: ef e3 98 25 <unknown>
59+
60+
ptrue p15.d
61+
// CHECK-INST: ptrue p15.d
62+
// CHECK-ENCODING: [0xef,0xe3,0xd8,0x25]
63+
// CHECK-ERROR: instruction requires: sve
64+
// CHECK-UNKNOWN: ef e3 d8 25 <unknown>
65+
66+
// ---------------------------------------------------------------------------//
67+
// Test available patterns
68+
// ---------------------------------------------------------------------------//
69+
70+
ptrue p7.s, #1
71+
// CHECK-INST: ptrue p7.s, vl1
72+
// CHECK-ENCODING: [0x27,0xe0,0x98,0x25]
73+
// CHECK-ERROR: instruction requires: sve
74+
// CHECK-UNKNOWN: 27 e0 98 25 <unknown>
75+
76+
ptrue p7.s, vl1
77+
// CHECK-INST: ptrue p7.s, vl1
78+
// CHECK-ENCODING: [0x27,0xe0,0x98,0x25]
79+
// CHECK-ERROR: instruction requires: sve
80+
// CHECK-UNKNOWN: 27 e0 98 25 <unknown>
81+
82+
ptrue p7.s, vl2
83+
// CHECK-INST: ptrue p7.s, vl2
84+
// CHECK-ENCODING: [0x47,0xe0,0x98,0x25]
85+
// CHECK-ERROR: instruction requires: sve
86+
// CHECK-UNKNOWN: 47 e0 98 25 <unknown>
87+
88+
ptrue p7.s, vl3
89+
// CHECK-INST: ptrue p7.s, vl3
90+
// CHECK-ENCODING: [0x67,0xe0,0x98,0x25]
91+
// CHECK-ERROR: instruction requires: sve
92+
// CHECK-UNKNOWN: 67 e0 98 25 <unknown>
93+
94+
ptrue p7.s, vl4
95+
// CHECK-INST: ptrue p7.s, vl4
96+
// CHECK-ENCODING: [0x87,0xe0,0x98,0x25]
97+
// CHECK-ERROR: instruction requires: sve
98+
// CHECK-UNKNOWN: 87 e0 98 25 <unknown>
99+
100+
ptrue p7.s, vl5
101+
// CHECK-INST: ptrue p7.s, vl5
102+
// CHECK-ENCODING: [0xa7,0xe0,0x98,0x25]
103+
// CHECK-ERROR: instruction requires: sve
104+
// CHECK-UNKNOWN: a7 e0 98 25 <unknown>
105+
106+
ptrue p7.s, vl6
107+
// CHECK-INST: ptrue p7.s, vl6
108+
// CHECK-ENCODING: [0xc7,0xe0,0x98,0x25]
109+
// CHECK-ERROR: instruction requires: sve
110+
// CHECK-UNKNOWN: c7 e0 98 25 <unknown>
111+
112+
ptrue p7.s, vl7
113+
// CHECK-INST: ptrue p7.s, vl7
114+
// CHECK-ENCODING: [0xe7,0xe0,0x98,0x25]
115+
// CHECK-ERROR: instruction requires: sve
116+
// CHECK-UNKNOWN: e7 e0 98 25 <unknown>
117+
118+
ptrue p7.s, vl8
119+
// CHECK-INST: ptrue p7.s, vl8
120+
// CHECK-ENCODING: [0x07,0xe1,0x98,0x25]
121+
// CHECK-ERROR: instruction requires: sve
122+
// CHECK-UNKNOWN: 07 e1 98 25 <unknown>
123+
124+
ptrue p7.s, vl16
125+
// CHECK-INST: ptrue p7.s, vl16
126+
// CHECK-ENCODING: [0x27,0xe1,0x98,0x25]
127+
// CHECK-ERROR: instruction requires: sve
128+
// CHECK-UNKNOWN: 27 e1 98 25 <unknown>
129+
130+
ptrue p7.s, vl32
131+
// CHECK-INST: ptrue p7.s, vl32
132+
// CHECK-ENCODING: [0x47,0xe1,0x98,0x25]
133+
// CHECK-ERROR: instruction requires: sve
134+
// CHECK-UNKNOWN: 47 e1 98 25 <unknown>
135+
136+
ptrue p7.s, vl64
137+
// CHECK-INST: ptrue p7.s, vl64
138+
// CHECK-ENCODING: [0x67,0xe1,0x98,0x25]
139+
// CHECK-ERROR: instruction requires: sve
140+
// CHECK-UNKNOWN: 67 e1 98 25 <unknown>
141+
142+
ptrue p7.s, vl128
143+
// CHECK-INST: ptrue p7.s, vl128
144+
// CHECK-ENCODING: [0x87,0xe1,0x98,0x25]
145+
// CHECK-ERROR: instruction requires: sve
146+
// CHECK-UNKNOWN: 87 e1 98 25 <unknown>
147+
148+
ptrue p7.s, vl256
149+
// CHECK-INST: ptrue p7.s, vl256
150+
// CHECK-ENCODING: [0xa7,0xe1,0x98,0x25]
151+
// CHECK-ERROR: instruction requires: sve
152+
// CHECK-UNKNOWN: a7 e1 98 25 <unknown>
153+
154+
ptrue p7.s, mul4
155+
// CHECK-INST: ptrue p7.s, mul4
156+
// CHECK-ENCODING: [0xa7,0xe3,0x98,0x25]
157+
// CHECK-ERROR: instruction requires: sve
158+
// CHECK-UNKNOWN: a7 e3 98 25 <unknown>
159+
160+
ptrue p7.s, mul3
161+
// CHECK-INST: ptrue p7.s, mul3
162+
// CHECK-ENCODING: [0xc7,0xe3,0x98,0x25]
163+
// CHECK-ERROR: instruction requires: sve
164+
// CHECK-UNKNOWN: c7 e3 98 25 <unknown>
165+
166+
ptrue p7.s, all
167+
// CHECK-INST: ptrue p7.s
168+
// CHECK-ENCODING: [0xe7,0xe3,0x98,0x25]
169+
// CHECK-ERROR: instruction requires: sve
170+
// CHECK-UNKNOWN: e7 e3 98 25 <unknown>
171+
172+
// ---------------------------------------------------------------------------//
173+
// Test immediate values not corresponding to a named pattern
174+
// ---------------------------------------------------------------------------//
175+
176+
ptrue p7.s, #14
177+
// CHECK-INST: ptrue p7.s, #14
178+
// CHECK-ENCODING: [0xc7,0xe1,0x98,0x25]
179+
// CHECK-ERROR: instruction requires: sve
180+
// CHECK-UNKNOWN: c7 e1 98 25 <unknown>
181+
182+
ptrue p7.s, #15
183+
// CHECK-INST: ptrue p7.s, #15
184+
// CHECK-ENCODING: [0xe7,0xe1,0x98,0x25]
185+
// CHECK-ERROR: instruction requires: sve
186+
// CHECK-UNKNOWN: e7 e1 98 25 <unknown>
187+
188+
ptrue p7.s, #16
189+
// CHECK-INST: ptrue p7.s, #16
190+
// CHECK-ENCODING: [0x07,0xe2,0x98,0x25]
191+
// CHECK-ERROR: instruction requires: sve
192+
// CHECK-UNKNOWN: 07 e2 98 25 <unknown>
193+
194+
ptrue p7.s, #17
195+
// CHECK-INST: ptrue p7.s, #17
196+
// CHECK-ENCODING: [0x27,0xe2,0x98,0x25]
197+
// CHECK-ERROR: instruction requires: sve
198+
// CHECK-UNKNOWN: 27 e2 98 25 <unknown>
199+
200+
ptrue p7.s, #18
201+
// CHECK-INST: ptrue p7.s, #18
202+
// CHECK-ENCODING: [0x47,0xe2,0x98,0x25]
203+
// CHECK-ERROR: instruction requires: sve
204+
// CHECK-UNKNOWN: 47 e2 98 25 <unknown>
205+
206+
ptrue p7.s, #19
207+
// CHECK-INST: ptrue p7.s, #19
208+
// CHECK-ENCODING: [0x67,0xe2,0x98,0x25]
209+
// CHECK-ERROR: instruction requires: sve
210+
// CHECK-UNKNOWN: 67 e2 98 25 <unknown>
211+
212+
ptrue p7.s, #20
213+
// CHECK-INST: ptrue p7.s, #20
214+
// CHECK-ENCODING: [0x87,0xe2,0x98,0x25]
215+
// CHECK-ERROR: instruction requires: sve
216+
// CHECK-UNKNOWN: 87 e2 98 25 <unknown>
217+
218+
ptrue p7.s, #21
219+
// CHECK-INST: ptrue p7.s, #21
220+
// CHECK-ENCODING: [0xa7,0xe2,0x98,0x25]
221+
// CHECK-ERROR: instruction requires: sve
222+
// CHECK-UNKNOWN: a7 e2 98 25 <unknown>
223+
224+
ptrue p7.s, #22
225+
// CHECK-INST: ptrue p7.s, #22
226+
// CHECK-ENCODING: [0xc7,0xe2,0x98,0x25]
227+
// CHECK-ERROR: instruction requires: sve
228+
// CHECK-UNKNOWN: c7 e2 98 25 <unknown>
229+
230+
ptrue p7.s, #23
231+
// CHECK-INST: ptrue p7.s, #23
232+
// CHECK-ENCODING: [0xe7,0xe2,0x98,0x25]
233+
// CHECK-ERROR: instruction requires: sve
234+
// CHECK-UNKNOWN: e7 e2 98 25 <unknown>
235+
236+
ptrue p7.s, #24
237+
// CHECK-INST: ptrue p7.s, #24
238+
// CHECK-ENCODING: [0x07,0xe3,0x98,0x25]
239+
// CHECK-ERROR: instruction requires: sve
240+
// CHECK-UNKNOWN: 07 e3 98 25 <unknown>
241+
242+
ptrue p7.s, #25
243+
// CHECK-INST: ptrue p7.s, #25
244+
// CHECK-ENCODING: [0x27,0xe3,0x98,0x25]
245+
// CHECK-ERROR: instruction requires: sve
246+
// CHECK-UNKNOWN: 27 e3 98 25 <unknown>
247+
248+
ptrue p7.s, #26
249+
// CHECK-INST: ptrue p7.s, #26
250+
// CHECK-ENCODING: [0x47,0xe3,0x98,0x25]
251+
// CHECK-ERROR: instruction requires: sve
252+
// CHECK-UNKNOWN: 47 e3 98 25 <unknown>
253+
254+
ptrue p7.s, #27
255+
// CHECK-INST: ptrue p7.s, #27
256+
// CHECK-ENCODING: [0x67,0xe3,0x98,0x25]
257+
// CHECK-ERROR: instruction requires: sve
258+
// CHECK-UNKNOWN: 67 e3 98 25 <unknown>
259+
260+
ptrue p7.s, #28
261+
// CHECK-INST: ptrue p7.s, #28
262+
// CHECK-ENCODING: [0x87,0xe3,0x98,0x25]
263+
// CHECK-ERROR: instruction requires: sve
264+
// CHECK-UNKNOWN: 87 e3 98 25 <unknown>

0 commit comments

Comments
 (0)