Skip to content

Commit b02eab9

Browse files
committed
[RISCV] Add scalable vector icmp ISel patterns
Original patch by @rogfer01. The RVV integer comparison instructions are defined in such a way that many LLVM operations are defined by using the "opposite" comparison instruction and swapping the operands. This is done in this patch in most cases, except for the mappings where the immediate range must be adjusted to accomodate: va < i --> vmsle{u}.vi vd, va, i-1, vm va >= i --> vmsgt{u}.vi vd, va, i-1, vm That is left for future optimization; this patch supports all operations but in the case of the missing mappings the immediate will be moved to a scalar register first. Since there are so many condition codes and operand cases to check, it was decided to reduce the test burden by only testing the "vscale x 8" vector types. Authored-by: Roger Ferrer Ibanez <[email protected]> Co-Authored-by: Fraser Cormack <[email protected]> Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D94168
1 parent 41d0609 commit b02eab9

File tree

3 files changed

+6195
-0
lines changed

3 files changed

+6195
-0
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ def SplatPat : ComplexPattern<vAny, 1, "selectVSplat", [], [], 1>;
3535
def SplatPat_simm5 : ComplexPattern<vAny, 1, "selectVSplatSimm5", []>;
3636
def SplatPat_uimm5 : ComplexPattern<vAny, 1, "selectVSplatUimm5", []>;
3737

38+
class SwapHelper<dag Prefix, dag A, dag B, dag Suffix, bit swap> {
39+
dag Value = !con(Prefix, !if(swap, B, A), !if(swap, A, B), Suffix);
40+
}
41+
3842
multiclass VPatUSLoadStoreSDNode<LLVMType type,
3943
LLVMType mask_type,
4044
int sew,
@@ -128,6 +132,66 @@ multiclass VPatBinarySDNode_VV_VX_VI<SDNode vop, string instruction_name,
128132
}
129133
}
130134

135+
multiclass VPatIntegerSetCCSDNode_VV<CondCode cc,
136+
string instruction_name,
137+
bit swap = 0> {
138+
foreach vti = AllIntegerVectors in {
139+
defvar instruction = !cast<Instruction>(instruction_name#"_VV_"#vti.LMul.MX);
140+
def : Pat<(vti.Mask (setcc (vti.Vector vti.RegClass:$rs1),
141+
(vti.Vector vti.RegClass:$rs2), cc)),
142+
SwapHelper<(instruction),
143+
(instruction vti.RegClass:$rs1),
144+
(instruction vti.RegClass:$rs2),
145+
(instruction VLMax, vti.SEW),
146+
swap>.Value>;
147+
}
148+
}
149+
150+
multiclass VPatIntegerSetCCSDNode_XI<CondCode cc,
151+
string instruction_name,
152+
string kind,
153+
ComplexPattern SplatPatKind,
154+
DAGOperand xop_kind,
155+
bit swap = 0> {
156+
foreach vti = AllIntegerVectors in {
157+
defvar instruction = !cast<Instruction>(instruction_name#_#kind#_#vti.LMul.MX);
158+
def : Pat<(vti.Mask (setcc (vti.Vector vti.RegClass:$rs1),
159+
(vti.Vector (SplatPatKind xop_kind:$rs2)), cc)),
160+
SwapHelper<(instruction),
161+
(instruction vti.RegClass:$rs1),
162+
(instruction xop_kind:$rs2),
163+
(instruction VLMax, vti.SEW),
164+
swap>.Value>;
165+
}
166+
}
167+
168+
multiclass VPatIntegerSetCCSDNode_VV_VX_VI<CondCode cc,
169+
string instruction_name,
170+
bit swap = 0> {
171+
defm : VPatIntegerSetCCSDNode_VV<cc, instruction_name, swap>;
172+
defm : VPatIntegerSetCCSDNode_XI<cc, instruction_name, "VX",
173+
SplatPat, GPR, swap>;
174+
defm : VPatIntegerSetCCSDNode_XI<cc, instruction_name, "VI",
175+
SplatPat_simm5, simm5, swap>;
176+
}
177+
178+
multiclass VPatIntegerSetCCSDNode_VV_VX<CondCode cc,
179+
string instruction_name,
180+
bit swap = 0> {
181+
defm : VPatIntegerSetCCSDNode_VV<cc, instruction_name, swap>;
182+
defm : VPatIntegerSetCCSDNode_XI<cc, instruction_name, "VX",
183+
SplatPat, GPR, swap>;
184+
}
185+
186+
multiclass VPatIntegerSetCCSDNode_VX_VI<CondCode cc,
187+
string instruction_name,
188+
bit swap = 0> {
189+
defm : VPatIntegerSetCCSDNode_XI<cc, instruction_name, "VX",
190+
SplatPat, GPR, swap>;
191+
defm : VPatIntegerSetCCSDNode_XI<cc, instruction_name, "VI",
192+
SplatPat_simm5, simm5, swap>;
193+
}
194+
131195
//===----------------------------------------------------------------------===//
132196
// Patterns.
133197
//===----------------------------------------------------------------------===//
@@ -164,6 +228,28 @@ defm "" : VPatBinarySDNode_VV_VX_VI<shl, "PseudoVSLL", uimm5>;
164228
defm "" : VPatBinarySDNode_VV_VX_VI<srl, "PseudoVSRL", uimm5>;
165229
defm "" : VPatBinarySDNode_VV_VX_VI<sra, "PseudoVSRA", uimm5>;
166230

231+
// 12.8. Vector Integer Comparison Instructions
232+
defm "" : VPatIntegerSetCCSDNode_VV_VX_VI<SETEQ, "PseudoVMSEQ">;
233+
defm "" : VPatIntegerSetCCSDNode_VV_VX_VI<SETNE, "PseudoVMSNE">;
234+
235+
// FIXME: Support immediate forms of these by choosing SLE decrementing the
236+
// immediate
237+
defm "" : VPatIntegerSetCCSDNode_VV_VX<SETLT, "PseudoVMSLT">;
238+
defm "" : VPatIntegerSetCCSDNode_VV_VX<SETULT, "PseudoVMSLTU">;
239+
240+
defm "" : VPatIntegerSetCCSDNode_VV<SETGT, "PseudoVMSLT", /*swap*/1>;
241+
defm "" : VPatIntegerSetCCSDNode_VV<SETUGT, "PseudoVMSLTU", /*swap*/1>;
242+
defm "" : VPatIntegerSetCCSDNode_VX_VI<SETGT, "PseudoVMSGT">;
243+
defm "" : VPatIntegerSetCCSDNode_VX_VI<SETUGT, "PseudoVMSGTU">;
244+
245+
defm "" : VPatIntegerSetCCSDNode_VV_VX_VI<SETLE, "PseudoVMSLE">;
246+
defm "" : VPatIntegerSetCCSDNode_VV_VX_VI<SETULE, "PseudoVMSLEU">;
247+
248+
// FIXME: Support immediate forms of these by choosing SGT and decrementing the
249+
// immediate
250+
defm "" : VPatIntegerSetCCSDNode_VV<SETGE, "PseudoVMSLE", /*swap*/1>;
251+
defm "" : VPatIntegerSetCCSDNode_VV<SETUGE, "PseudoVMSLEU", /*swap*/1>;
252+
167253
// 12.9. Vector Integer Min/Max Instructions
168254
defm "" : VPatBinarySDNode_VV_VX<umin, "PseudoVMINU">;
169255
defm "" : VPatBinarySDNode_VV_VX<smin, "PseudoVMIN">;

0 commit comments

Comments
 (0)