@@ -34,65 +34,6 @@ static cl::opt<unsigned> SLPMaxVF(
34
34
" exclusively by SLP vectorizer." ),
35
35
cl::Hidden);
36
36
37
- InstructionCost
38
- RISCVTTIImpl::getRISCVInstructionCost (ArrayRef<unsigned > OpCodes, MVT VT,
39
- TTI::TargetCostKind CostKind) {
40
- size_t NumInstr = OpCodes.size ();
41
- if (CostKind == TTI::TCK_CodeSize)
42
- return NumInstr;
43
- InstructionCost LMULCost = TLI->getLMULCost (VT);
44
- if ((CostKind != TTI::TCK_RecipThroughput) && (CostKind != TTI::TCK_Latency))
45
- return LMULCost * NumInstr;
46
- InstructionCost Cost = 0 ;
47
- for (auto Op : OpCodes) {
48
- switch (Op) {
49
- case RISCV::VRGATHER_VI:
50
- Cost += TLI->getVRGatherVICost (VT);
51
- break ;
52
- case RISCV::VRGATHER_VV:
53
- Cost += TLI->getVRGatherVVCost (VT);
54
- break ;
55
- case RISCV::VSLIDEUP_VI:
56
- case RISCV::VSLIDEDOWN_VI:
57
- Cost += TLI->getVSlideVICost (VT);
58
- break ;
59
- case RISCV::VSLIDEUP_VX:
60
- case RISCV::VSLIDEDOWN_VX:
61
- Cost += TLI->getVSlideVXCost (VT);
62
- break ;
63
- case RISCV::VREDMAX_VS:
64
- case RISCV::VREDMIN_VS:
65
- case RISCV::VREDMAXU_VS:
66
- case RISCV::VREDMINU_VS:
67
- case RISCV::VREDSUM_VS:
68
- case RISCV::VREDAND_VS:
69
- case RISCV::VREDOR_VS:
70
- case RISCV::VREDXOR_VS:
71
- case RISCV::VFREDMAX_VS:
72
- case RISCV::VFREDMIN_VS:
73
- case RISCV::VFREDUSUM_VS: {
74
- unsigned VL = VT.getVectorMinNumElements ();
75
- if (!VT.isFixedLengthVector ())
76
- VL *= *getVScaleForTuning ();
77
- Cost += Log2_32_Ceil (VL);
78
- break ;
79
- }
80
- case RISCV::VFREDOSUM_VS: {
81
- unsigned VL = VT.getVectorMinNumElements ();
82
- if (!VT.isFixedLengthVector ())
83
- VL *= *getVScaleForTuning ();
84
- Cost += VL;
85
- break ;
86
- }
87
- case RISCV::VMV_S_X:
88
- // FIXME: VMV_S_X doesn't use LMUL, the cost should be 1
89
- default :
90
- Cost += LMULCost;
91
- }
92
- }
93
- return Cost;
94
- }
95
-
96
37
InstructionCost RISCVTTIImpl::getIntImmCost (const APInt &Imm, Type *Ty,
97
38
TTI::TargetCostKind CostKind) {
98
39
assert (Ty->isIntegerTy () &&
@@ -340,8 +281,7 @@ InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
340
281
// Example sequence:
341
282
// vnsrl.wi v10, v8, 0
342
283
if (equal (DeinterleaveMask, Mask))
343
- return LT.first * getRISCVInstructionCost (RISCV::VNSRL_WI,
344
- LT.second , CostKind);
284
+ return LT.first * TLI->getLMULCost (LT.second );
345
285
}
346
286
}
347
287
}
@@ -352,8 +292,7 @@ InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
352
292
LT.second .getVectorNumElements () <= 256 )) {
353
293
VectorType *IdxTy = getVRGatherIndexType (LT.second , *ST, Tp->getContext ());
354
294
InstructionCost IndexCost = getConstantPoolLoadCost (IdxTy, CostKind);
355
- return IndexCost +
356
- getRISCVInstructionCost (RISCV::VRGATHER_VV, LT.second , CostKind);
295
+ return IndexCost + TLI->getVRGatherVVCost (LT.second );
357
296
}
358
297
[[fallthrough]];
359
298
}
@@ -371,10 +310,7 @@ InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
371
310
VectorType *MaskTy = VectorType::get (IntegerType::getInt1Ty (C), EC);
372
311
InstructionCost IndexCost = getConstantPoolLoadCost (IdxTy, CostKind);
373
312
InstructionCost MaskCost = getConstantPoolLoadCost (MaskTy, CostKind);
374
- return 2 * IndexCost +
375
- getRISCVInstructionCost ({RISCV::VRGATHER_VV, RISCV::VRGATHER_VV},
376
- LT.second , CostKind) +
377
- MaskCost;
313
+ return 2 * IndexCost + 2 * TLI->getVRGatherVVCost (LT.second ) + MaskCost;
378
314
}
379
315
[[fallthrough]];
380
316
}
@@ -429,24 +365,19 @@ InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
429
365
// Example sequence:
430
366
// vsetivli zero, 4, e8, mf2, tu, ma (ignored)
431
367
// vslidedown.vi v8, v9, 2
432
- return LT.first *
433
- getRISCVInstructionCost (RISCV::VSLIDEDOWN_VI, LT.second , CostKind);
368
+ return LT.first * TLI->getVSlideCost (LT.second );
434
369
case TTI::SK_InsertSubvector:
435
370
// Example sequence:
436
371
// vsetivli zero, 4, e8, mf2, tu, ma (ignored)
437
372
// vslideup.vi v8, v9, 2
438
- return LT.first *
439
- getRISCVInstructionCost (RISCV::VSLIDEUP_VI, LT.second , CostKind);
373
+ return LT.first * TLI->getVSlideCost (LT.second );
440
374
case TTI::SK_Select: {
441
375
// Example sequence:
442
376
// li a0, 90
443
377
// vsetivli zero, 8, e8, mf2, ta, ma (ignored)
444
378
// vmv.s.x v0, a0
445
379
// vmerge.vvm v8, v9, v8, v0
446
- return LT.first *
447
- (TLI->getLMULCost (LT.second ) + // FIXME: should be 1 for li
448
- getRISCVInstructionCost ({RISCV::VMV_S_X, RISCV::VMERGE_VVM},
449
- LT.second , CostKind));
380
+ return LT.first * 3 * TLI->getLMULCost (LT.second );
450
381
}
451
382
case TTI::SK_Broadcast: {
452
383
bool HasScalar = (Args.size () > 0 ) && (Operator::getOpcode (Args[0 ]) ==
@@ -458,10 +389,7 @@ InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
458
389
// vsetivli zero, 2, e8, mf8, ta, ma (ignored)
459
390
// vmv.v.x v8, a0
460
391
// vmsne.vi v0, v8, 0
461
- return LT.first *
462
- (TLI->getLMULCost (LT.second ) + // FIXME: should be 1 for andi
463
- getRISCVInstructionCost ({RISCV::VMV_V_X, RISCV::VMSNE_VI},
464
- LT.second , CostKind));
392
+ return LT.first * TLI->getLMULCost (LT.second ) * 3 ;
465
393
}
466
394
// Example sequence:
467
395
// vsetivli zero, 2, e8, mf8, ta, mu (ignored)
@@ -472,40 +400,24 @@ InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
472
400
// vmv.v.x v8, a0
473
401
// vmsne.vi v0, v8, 0
474
402
475
- return LT.first *
476
- (TLI->getLMULCost (LT.second ) + // FIXME: this should be 1 for andi
477
- TLI->getLMULCost (
478
- LT.second ) + // FIXME: vmv.x.s is the same as extractelement
479
- getRISCVInstructionCost ({RISCV::VMV_V_I, RISCV::VMERGE_VIM,
480
- RISCV::VMV_V_X, RISCV::VMSNE_VI},
481
- LT.second , CostKind));
403
+ return LT.first * TLI->getLMULCost (LT.second ) * 6 ;
482
404
}
483
405
484
406
if (HasScalar) {
485
407
// Example sequence:
486
408
// vmv.v.x v8, a0
487
- return LT.first *
488
- getRISCVInstructionCost (RISCV::VMV_V_X, LT.second , CostKind);
409
+ return LT.first * TLI->getLMULCost (LT.second );
489
410
}
490
411
491
412
// Example sequence:
492
413
// vrgather.vi v9, v8, 0
493
- return LT.first *
494
- getRISCVInstructionCost (RISCV::VRGATHER_VI, LT.second , CostKind);
414
+ return LT.first * TLI->getVRGatherVICost (LT.second );
495
415
}
496
- case TTI::SK_Splice: {
416
+ case TTI::SK_Splice:
497
417
// vslidedown+vslideup.
498
418
// TODO: Multiplying by LT.first implies this legalizes into multiple copies
499
419
// of similar code, but I think we expand through memory.
500
- ArrayRef<unsigned > Opcodes;
501
- if (Index >= 0 && Index < 32 )
502
- Opcodes = {RISCV::VSLIDEDOWN_VI, RISCV::VSLIDEUP_VX};
503
- else if (Index < 0 && Index > -32 )
504
- Opcodes = {RISCV::VSLIDEDOWN_VX, RISCV::VSLIDEUP_VI};
505
- else
506
- Opcodes = {RISCV::VSLIDEDOWN_VX, RISCV::VSLIDEUP_VX};
507
- return LT.first * getRISCVInstructionCost (Opcodes, LT.second , CostKind);
508
- }
420
+ return 2 * LT.first * TLI->getVSlideCost (LT.second );
509
421
case TTI::SK_Reverse: {
510
422
// TODO: Cases to improve here:
511
423
// * Illegal vector types
@@ -525,9 +437,7 @@ InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
525
437
if (LT.second .isFixedLengthVector ())
526
438
// vrsub.vi has a 5 bit immediate field, otherwise an li suffices
527
439
LenCost = isInt<5 >(LT.second .getVectorNumElements () - 1 ) ? 0 : 1 ;
528
- // FIXME: replace the constant `2` below with cost of {VID_V,VRSUB_VX}
529
- InstructionCost GatherCost =
530
- 2 + getRISCVInstructionCost (RISCV::VRGATHER_VV, LT.second , CostKind);
440
+ InstructionCost GatherCost = 2 + TLI->getVRGatherVVCost (LT.second );
531
441
// Mask operation additionally required extend and truncate
532
442
InstructionCost ExtendCost = Tp->getElementType ()->isIntegerTy (1 ) ? 3 : 0 ;
533
443
return LT.first * (LenCost + GatherCost + ExtendCost);
0 commit comments