Skip to content

Commit 784204f

Browse files
kaz7Simon Moll
authored andcommitted
[VE] add, sub, left/right shift isel patterns
Summary: Add, sub, left/right shift isel patterns and tests for i32/i64 and fp32/fp64. Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D73207
1 parent 41784be commit 784204f

File tree

5 files changed

+883
-12
lines changed

5 files changed

+883
-12
lines changed

llvm/lib/Target/VE/VEInstrInfo.td

Lines changed: 177 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,6 @@ multiclass RMm<string opcStr, bits<8>opc,
255255
}
256256
}
257257

258-
// Multiclass for RR type instructions
259-
260258
multiclass RRmrr<string opcStr, bits<8>opc,
261259
RegisterClass RCo, ValueType Tyo,
262260
RegisterClass RCi, ValueType Tyi,
@@ -279,6 +277,16 @@ multiclass RRmri<string opcStr, bits<8>opc,
279277
{ let cy = 0; let cz = 1; let hasSideEffects = 0; }
280278
}
281279

280+
multiclass RRmir<string opcStr, bits<8>opc,
281+
RegisterClass RCo, ValueType Tyo,
282+
RegisterClass RCi, ValueType Tyi, Operand immOp,
283+
SDPatternOperator OpNode=null_frag> {
284+
def ri : RR<opc, (outs RCo:$sx), (ins immOp:$sy, RCi:$sz),
285+
!strconcat(opcStr, " $sx, $sy, $sz"),
286+
[(set Tyo:$sx, (OpNode (Tyi simm7:$sy), Tyi:$sz))]>
287+
{ let cy = 0; let cz = 1; let hasSideEffects = 0; }
288+
}
289+
282290
multiclass RRmiz<string opcStr, bits<8>opc,
283291
RegisterClass RCo, ValueType Tyo,
284292
RegisterClass RCi, ValueType Tyi, Operand immOp,
@@ -324,7 +332,8 @@ multiclass RRNDmim<string opcStr, bits<8>opc,
324332
// Used by add, mul, div, and similar commutative instructions
325333
// The order of operands are "$sx, $sy, $sz"
326334

327-
multiclass RRm<string opcStr, bits<8>opc, RegisterClass RC, ValueType Ty,
335+
multiclass RRm<string opcStr, bits<8>opc,
336+
RegisterClass RC, ValueType Ty,
328337
Operand immOp, Operand immOp2,
329338
SDPatternOperator OpNode=null_frag> :
330339
RRmrr<opcStr, opc, RC, Ty, RC, Ty, OpNode>,
@@ -333,13 +342,34 @@ multiclass RRm<string opcStr, bits<8>opc, RegisterClass RC, ValueType Ty,
333342
RRNDmrm<opcStr, opc, RC, Ty, RC, Ty, immOp2>,
334343
RRNDmim<opcStr, opc, RC, Ty, RC, Ty, immOp, immOp2>;
335344

345+
// Used by sub, and similar not commutative instructions
346+
// The order of operands are "$sx, $sy, $sz"
347+
348+
multiclass RRNCm<string opcStr, bits<8>opc,
349+
RegisterClass RC, ValueType Ty, Operand immOp, Operand immOp2,
350+
SDPatternOperator OpNode=null_frag> :
351+
RRmrr<opcStr, opc, RC, Ty, RC, Ty, OpNode>,
352+
RRmir<opcStr, opc, RC, Ty, RC, Ty, immOp, OpNode>,
353+
RRmiz<opcStr, opc, RC, Ty, RC, Ty, immOp, OpNode>,
354+
RRNDmrm<opcStr, opc, RC, Ty, RC, Ty, immOp2>,
355+
RRNDmim<opcStr, opc, RC, Ty, RC, Ty, immOp, immOp2>;
336356

337357
// Multiclass for RR type instructions
338358
// Used by sra, sla, sll, and similar instructions
339359
// The order of operands are "$sx, $sz, $sy"
340360

341-
multiclass RRIm<string opcStr, bits<8>opc, SDNode OpNode,
342-
RegisterClass RC, ValueType Ty, Operand immOp, Operand immOp2> {
361+
multiclass RRIm<string opcStr, bits<8>opc,
362+
RegisterClass RC, ValueType Ty,
363+
Operand immOp, Operand immOp2,
364+
SDPatternOperator OpNode=null_frag> {
365+
def rr : RR<
366+
opc, (outs RC:$sx), (ins RC:$sz, I32:$sy),
367+
!strconcat(opcStr, " $sx, $sz, $sy"),
368+
[(set Ty:$sx, (OpNode Ty:$sz, i32:$sy))]> {
369+
let cy = 1;
370+
let cz = 1;
371+
let hasSideEffects = 0;
372+
}
343373
def ri : RR<
344374
opc, (outs RC:$sx), (ins RC:$sz, immOp:$sy),
345375
!strconcat(opcStr, " $sx, $sz, $sy"),
@@ -348,6 +378,104 @@ multiclass RRIm<string opcStr, bits<8>opc, SDNode OpNode,
348378
let cz = 1;
349379
let hasSideEffects = 0;
350380
}
381+
def rm0 : RR<
382+
opc, (outs RC:$sx), (ins immOp2:$sz, I32:$sy),
383+
!strconcat(opcStr, " $sx, (${sz})0, $sy")> {
384+
let cy = 1;
385+
let cz = 0;
386+
let sz{6} = 1;
387+
let hasSideEffects = 0;
388+
}
389+
def rm1 : RR<
390+
opc, (outs RC:$sx), (ins immOp2:$sz, I32:$sy),
391+
!strconcat(opcStr, " $sx, (${sz})1, $sy")> {
392+
let cy = 1;
393+
let cz = 0;
394+
let hasSideEffects = 0;
395+
}
396+
def im0 : RR<
397+
opc, (outs RC:$sx), (ins immOp2:$sz, immOp:$sy),
398+
!strconcat(opcStr, " $sx, (${sz})0, $sy")> {
399+
let cy = 0;
400+
let cz = 0;
401+
let sz{6} = 1;
402+
let hasSideEffects = 0;
403+
}
404+
def im1 : RR<
405+
opc, (outs RC:$sx), (ins immOp2:$sz, immOp:$sy),
406+
!strconcat(opcStr, " $sx, (${sz})1, $sy")> {
407+
let cy = 0;
408+
let cz = 0;
409+
let hasSideEffects = 0;
410+
}
411+
def zi : RR<
412+
opc, (outs RC:$sx), (ins immOp:$sy),
413+
!strconcat(opcStr, " $sx, $sy"),
414+
[(set Ty:$sx, (OpNode 0, (i32 simm7:$sy)))]> {
415+
let cy = 0;
416+
let cz = 0;
417+
let sz = 0;
418+
let hasSideEffects = 0;
419+
}
420+
}
421+
422+
// Multiclass for RR type instructions without dag pattern
423+
// Used by sra.w.zx, sla.w.zx, and others
424+
425+
multiclass RRINDm<string opcStr, bits<8>opc,
426+
RegisterClass RC, ValueType Ty, Operand immOp, Operand immOp2> {
427+
def rr : RR<
428+
opc, (outs RC:$sx), (ins RC:$sz, I32:$sy),
429+
!strconcat(opcStr, " $sx, $sz, $sy")> {
430+
let cy = 1;
431+
let cz = 1;
432+
let hasSideEffects = 0;
433+
}
434+
def ri : RR<
435+
opc, (outs RC:$sx), (ins RC:$sz, immOp:$sy),
436+
!strconcat(opcStr, " $sx, $sz, $sy")> {
437+
let cy = 0;
438+
let cz = 1;
439+
let hasSideEffects = 0;
440+
}
441+
def rm0 : RR<
442+
opc, (outs RC:$sx), (ins immOp2:$sz, I32:$sy),
443+
!strconcat(opcStr, " $sx, (${sz})0, $sy")> {
444+
let cy = 1;
445+
let cz = 0;
446+
let sz{6} = 1;
447+
let hasSideEffects = 0;
448+
}
449+
def rm1 : RR<
450+
opc, (outs RC:$sx), (ins immOp2:$sz, I32:$sy),
451+
!strconcat(opcStr, " $sx, (${sz})1, $sy")> {
452+
let cy = 1;
453+
let cz = 0;
454+
let hasSideEffects = 0;
455+
}
456+
def im0 : RR<
457+
opc, (outs RC:$sx), (ins immOp2:$sz, immOp:$sy),
458+
!strconcat(opcStr, " $sx, (${sz})0, $sy")> {
459+
let cy = 0;
460+
let cz = 0;
461+
let sz{6} = 1;
462+
let hasSideEffects = 0;
463+
}
464+
def im1 : RR<
465+
opc, (outs RC:$sx), (ins immOp2:$sz, immOp:$sy),
466+
!strconcat(opcStr, " $sx, (${sz})1, $sy")> {
467+
let cy = 0;
468+
let cz = 0;
469+
let hasSideEffects = 0;
470+
}
471+
def zi : RR<
472+
opc, (outs RC:$sx), (ins immOp:$sy),
473+
!strconcat(opcStr, " $sx, $sy")> {
474+
let cy = 0;
475+
let cz = 0;
476+
let sz = 0;
477+
let hasSideEffects = 0;
478+
}
351479
}
352480

353481
// Multiclass for RR type instructions
@@ -407,27 +535,49 @@ defm CMOVS : RRCMOVm<"cmov.s.${cf}", 0x3B, F32, f32, simm7Op64, uimm6Op32>;
407535

408536
// LEA and LEASL instruction (load 32 bit imm to low or high part)
409537
let cx = 0 in
410-
defm LEA : RMm<"lea", 0x06, I64, i64, simm7Op64, simm32Op64>;
538+
defm LEA : RMm<"lea", 0x06, I64, i64, simm7Op64, simm32Op64, add>;
411539
let cx = 1 in
412540
defm LEASL : RMm<"lea.sl", 0x06, I64, i64, simm7Op64, simm32Op64>;
413541
let isCodeGenOnly = 1 in {
414542
let cx = 0 in
415-
defm LEA32 : RMm<"lea", 0x06, I32, i32, simm7Op32, simm32Op32>;
543+
defm LEA32 : RMm<"lea", 0x06, I32, i32, simm7Op32, simm32Op32, add>;
416544
}
417545

418546

419547
// 5.3.2.2. Fixed-Point Arithmetic Operation Instructions
420548

549+
// ADD instruction
550+
let cx = 0 in
551+
defm ADD : RRm<"addu.l", 0x48, I64, i64, simm7Op64, uimm6Op64>;
552+
let cx = 1 in
553+
defm ADDUW : RRm<"addu.w", 0x48, I32, i32, simm7Op32, uimm6Op32>;
554+
421555
// ADS instruction
422556
let cx = 0 in
423557
defm ADS : RRm<"adds.w.sx", 0x4A, I32, i32, simm7Op32, uimm6Op32, add>;
424558
let cx = 1 in
425-
defm ADSU : RRm<"adds.w.zx", 0x4A, I32, i32, simm7Op32, uimm6Op32, add>;
559+
defm ADSU : RRm<"adds.w.zx", 0x4A, I32, i32, simm7Op32, uimm6Op32>;
426560

427561
// ADX instruction
428562
let cx = 0 in
429563
defm ADX : RRm<"adds.l", 0x59, I64, i64, simm7Op64, uimm6Op64, add>;
430564

565+
// SUB instruction
566+
let cx = 0 in
567+
defm SUB : RRm<"subu.l", 0x58, I64, i64, simm7Op64, uimm6Op64>;
568+
let cx = 1 in
569+
defm SUBUW : RRm<"subu.w", 0x58, I32, i32, simm7Op32, uimm6Op32>;
570+
571+
// SBS instruction
572+
let cx = 0 in
573+
defm SBS : RRNCm<"subs.w.sx", 0x5A, I32, i32, simm7Op32, uimm6Op32, sub>;
574+
let cx = 1 in
575+
defm SBSU : RRm<"subs.w.zx", 0x5A, I32, i32, simm7Op32, uimm6Op32>;
576+
577+
// SBX instruction
578+
let cx = 0 in
579+
defm SBX : RRNCm<"subs.l", 0x5B, I64, i64, simm7Op64, uimm6Op64, sub>;
580+
431581
// CMP instruction
432582
let cx = 0 in
433583
defm CMP : RRm<"cmpu.l", 0x55, I64, i64, simm7Op64, uimm6Op64>;
@@ -463,6 +613,7 @@ let cx = 1, cw = 0 in defm CMSi :
463613
let cx = 0 in {
464614
defm AND : RRm<"and", 0x44, I64, i64, simm7Op64, uimm6Op64, and>;
465615
defm OR : RRm<"or", 0x45, I64, i64, simm7Op64, uimm6Op64, or>;
616+
defm XOR : RRm<"xor", 0x46, I64, i64, simm7Op64, uimm6Op64, xor>;
466617
let isCodeGenOnly = 1 in {
467618
defm AND32 : RRm<"and", 0x44, I32, i32, simm7Op32, uimm6Op32, and>;
468619
defm OR32 : RRm<"or", 0x45, I32, i32, simm7Op32, uimm6Op32, or>;
@@ -474,15 +625,29 @@ let cx = 0 in {
474625
// 5.3.2.4 Shift Instructions
475626

476627
let cx = 0 in
477-
defm SRAX : RRIm<"sra.l", 0x77, sra, I64, i64, simm7Op32, uimm6Op64>;
628+
defm SRAX : RRIm<"sra.l", 0x77, I64, i64, simm7Op32, uimm6Op64, sra>;
478629
let cx = 0 in
479-
defm SRA : RRIm<"sra.w.sx", 0x76, sra, I32, i32, simm7Op32, uimm6Op32>;
630+
defm SRA : RRIm<"sra.w.sx", 0x76, I32, i32, simm7Op32, uimm6Op32, sra>;
631+
let cx = 1 in
632+
defm SRAU : RRINDm<"sra.w.zx", 0x76, I32, i32, simm7Op32, uimm6Op32>;
480633

481634
let cx = 0 in
482-
defm SLL : RRIm<"sll", 0x65, shl, I64, i64, simm7Op32, uimm6Op64>;
635+
defm SLL : RRIm<"sll", 0x65, I64, i64, simm7Op32, uimm6Op64, shl>;
483636
let cx = 0 in
484-
defm SLA : RRIm<"sla.w.sx", 0x66, shl, I32, i32, simm7Op32, uimm6Op32>;
637+
defm SLA : RRIm<"sla.w.sx", 0x66, I32, i32, simm7Op32, uimm6Op32, shl>;
638+
let cx = 1 in
639+
defm SLAU : RRINDm<"sla.w.zx", 0x66, I32, i32, simm7Op32, uimm6Op32>;
640+
let cx = 0 in
641+
defm SRL : RRIm<"srl", 0x75, I64, i64, simm7Op32, uimm6Op64, srl>;
642+
643+
def : Pat<(i32 (srl i32:$src, (i32 simm7:$val))),
644+
(EXTRACT_SUBREG (SRLri (ANDrm0 (INSERT_SUBREG (i64 (IMPLICIT_DEF)),
645+
$src, sub_i32), 32), imm:$val), sub_i32)>;
646+
def : Pat<(i32 (srl i32:$src, i32:$val)),
647+
(EXTRACT_SUBREG (SRLrr (ANDrm0 (INSERT_SUBREG (i64 (IMPLICIT_DEF)),
648+
$src, sub_i32), 32), $val), sub_i32)>;
485649

650+
// 5.3.2.5. Floating-point Arithmetic Operation Instructions
486651
// FCP instruction
487652
let cx = 0 in
488653
defm FCP : RRm<"fcmp.d", 0x7E, I64, f64, simm7Op64, uimm6Op64>;

0 commit comments

Comments
 (0)