@@ -4262,6 +4262,37 @@ X86TTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
4262
4262
}
4263
4263
4264
4264
if (ISD != ISD::DELETED_NODE) {
4265
+ auto adjustTableCost = [&](int ISD, unsigned Cost,
4266
+ std::pair<InstructionCost, MVT> LT,
4267
+ FastMathFlags FMF) -> InstructionCost {
4268
+ InstructionCost LegalizationCost = LT.first ;
4269
+ MVT MTy = LT.second ;
4270
+
4271
+ // If there are no NANs to deal with, then these are reduced to a
4272
+ // single MIN** or MAX** instruction instead of the MIN/CMP/SELECT that we
4273
+ // assume is used in the non-fast case.
4274
+ if (ISD == ISD::FMAXNUM || ISD == ISD::FMINNUM) {
4275
+ if (FMF.noNaNs ())
4276
+ return LegalizationCost * 1 ;
4277
+ }
4278
+
4279
+ // For cases where some ops can be folded into a load/store, assume free.
4280
+ if (MTy.isScalarInteger ()) {
4281
+ if (ISD == ISD::BSWAP && ST->hasMOVBE () && ST->hasFastMOVBE ()) {
4282
+ if (const Instruction *II = ICA.getInst ()) {
4283
+ if (II->hasOneUse () && isa<StoreInst>(II->user_back ()))
4284
+ return TTI::TCC_Free;
4285
+ if (auto *LI = dyn_cast<LoadInst>(II->getOperand (0 ))) {
4286
+ if (LI->hasOneUse ())
4287
+ return TTI::TCC_Free;
4288
+ }
4289
+ }
4290
+ }
4291
+ }
4292
+
4293
+ return LegalizationCost * (int )Cost;
4294
+ };
4295
+
4265
4296
// Legalize the type.
4266
4297
std::pair<InstructionCost, MVT> LT = getTypeLegalizationCost (OpTy);
4267
4298
MVT MTy = LT.second ;
@@ -4280,180 +4311,132 @@ X86TTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
4280
4311
if (ISD == ISD::FSQRT && CostKind == TTI::TCK_CodeSize)
4281
4312
return LT.first ;
4282
4313
4283
- auto adjustTableCost = [](int ISD, unsigned Cost,
4284
- InstructionCost LegalizationCost,
4285
- FastMathFlags FMF) {
4286
- // If there are no NANs to deal with, then these are reduced to a
4287
- // single MIN** or MAX** instruction instead of the MIN/CMP/SELECT that we
4288
- // assume is used in the non-fast case.
4289
- if (ISD == ISD::FMAXNUM || ISD == ISD::FMINNUM) {
4290
- if (FMF.noNaNs ())
4291
- return LegalizationCost * 1 ;
4292
- }
4293
- return LegalizationCost * (int )Cost;
4294
- };
4295
-
4296
4314
if (ST->useGLMDivSqrtCosts ())
4297
4315
if (const auto *Entry = CostTableLookup (GLMCostTbl, ISD, MTy))
4298
4316
if (auto KindCost = Entry->Cost [CostKind])
4299
- return adjustTableCost (Entry->ISD , *KindCost, LT.first ,
4300
- ICA.getFlags ());
4317
+ return adjustTableCost (Entry->ISD , *KindCost, LT, ICA.getFlags ());
4301
4318
4302
4319
if (ST->useSLMArithCosts ())
4303
4320
if (const auto *Entry = CostTableLookup (SLMCostTbl, ISD, MTy))
4304
4321
if (auto KindCost = Entry->Cost [CostKind])
4305
- return adjustTableCost (Entry->ISD , *KindCost, LT.first ,
4306
- ICA.getFlags ());
4322
+ return adjustTableCost (Entry->ISD , *KindCost, LT, ICA.getFlags ());
4307
4323
4308
4324
if (ST->hasVBMI2 ())
4309
4325
if (const auto *Entry = CostTableLookup (AVX512VBMI2CostTbl, ISD, MTy))
4310
4326
if (auto KindCost = Entry->Cost [CostKind])
4311
- return adjustTableCost (Entry->ISD , *KindCost, LT.first ,
4312
- ICA.getFlags ());
4327
+ return adjustTableCost (Entry->ISD , *KindCost, LT, ICA.getFlags ());
4313
4328
4314
4329
if (ST->hasBITALG ())
4315
4330
if (const auto *Entry = CostTableLookup (AVX512BITALGCostTbl, ISD, MTy))
4316
4331
if (auto KindCost = Entry->Cost [CostKind])
4317
- return adjustTableCost (Entry->ISD , *KindCost, LT.first ,
4318
- ICA.getFlags ());
4332
+ return adjustTableCost (Entry->ISD , *KindCost, LT, ICA.getFlags ());
4319
4333
4320
4334
if (ST->hasVPOPCNTDQ ())
4321
4335
if (const auto *Entry = CostTableLookup (AVX512VPOPCNTDQCostTbl, ISD, MTy))
4322
4336
if (auto KindCost = Entry->Cost [CostKind])
4323
- return adjustTableCost (Entry->ISD , *KindCost, LT.first ,
4324
- ICA.getFlags ());
4337
+ return adjustTableCost (Entry->ISD , *KindCost, LT, ICA.getFlags ());
4325
4338
4326
4339
if (ST->hasGFNI ())
4327
4340
if (const auto *Entry = CostTableLookup (GFNICostTbl, ISD, MTy))
4328
4341
if (auto KindCost = Entry->Cost [CostKind])
4329
- return adjustTableCost (Entry->ISD , *KindCost, LT.first ,
4330
- ICA.getFlags ());
4342
+ return adjustTableCost (Entry->ISD , *KindCost, LT, ICA.getFlags ());
4331
4343
4332
4344
if (ST->hasCDI ())
4333
4345
if (const auto *Entry = CostTableLookup (AVX512CDCostTbl, ISD, MTy))
4334
4346
if (auto KindCost = Entry->Cost [CostKind])
4335
- return adjustTableCost (Entry->ISD , *KindCost, LT.first ,
4336
- ICA.getFlags ());
4347
+ return adjustTableCost (Entry->ISD , *KindCost, LT, ICA.getFlags ());
4337
4348
4338
4349
if (ST->hasBWI ())
4339
4350
if (const auto *Entry = CostTableLookup (AVX512BWCostTbl, ISD, MTy))
4340
4351
if (auto KindCost = Entry->Cost [CostKind])
4341
- return adjustTableCost (Entry->ISD , *KindCost, LT.first ,
4342
- ICA.getFlags ());
4352
+ return adjustTableCost (Entry->ISD , *KindCost, LT, ICA.getFlags ());
4343
4353
4344
4354
if (ST->hasAVX512 ())
4345
4355
if (const auto *Entry = CostTableLookup (AVX512CostTbl, ISD, MTy))
4346
4356
if (auto KindCost = Entry->Cost [CostKind])
4347
- return adjustTableCost (Entry->ISD , *KindCost, LT.first ,
4348
- ICA.getFlags ());
4357
+ return adjustTableCost (Entry->ISD , *KindCost, LT, ICA.getFlags ());
4349
4358
4350
4359
if (ST->hasXOP ())
4351
4360
if (const auto *Entry = CostTableLookup (XOPCostTbl, ISD, MTy))
4352
4361
if (auto KindCost = Entry->Cost [CostKind])
4353
- return adjustTableCost (Entry->ISD , *KindCost, LT.first ,
4354
- ICA.getFlags ());
4362
+ return adjustTableCost (Entry->ISD , *KindCost, LT, ICA.getFlags ());
4355
4363
4356
4364
if (ST->hasAVX2 ())
4357
4365
if (const auto *Entry = CostTableLookup (AVX2CostTbl, ISD, MTy))
4358
4366
if (auto KindCost = Entry->Cost [CostKind])
4359
- return adjustTableCost (Entry->ISD , *KindCost, LT.first ,
4360
- ICA.getFlags ());
4367
+ return adjustTableCost (Entry->ISD , *KindCost, LT, ICA.getFlags ());
4361
4368
4362
4369
if (ST->hasAVX ())
4363
4370
if (const auto *Entry = CostTableLookup (AVX1CostTbl, ISD, MTy))
4364
4371
if (auto KindCost = Entry->Cost [CostKind])
4365
- return adjustTableCost (Entry->ISD , *KindCost, LT.first ,
4366
- ICA.getFlags ());
4372
+ return adjustTableCost (Entry->ISD , *KindCost, LT, ICA.getFlags ());
4367
4373
4368
4374
if (ST->hasSSE42 ())
4369
4375
if (const auto *Entry = CostTableLookup (SSE42CostTbl, ISD, MTy))
4370
4376
if (auto KindCost = Entry->Cost [CostKind])
4371
- return adjustTableCost (Entry->ISD , *KindCost, LT.first ,
4372
- ICA.getFlags ());
4377
+ return adjustTableCost (Entry->ISD , *KindCost, LT, ICA.getFlags ());
4373
4378
4374
4379
if (ST->hasSSE41 ())
4375
4380
if (const auto *Entry = CostTableLookup (SSE41CostTbl, ISD, MTy))
4376
4381
if (auto KindCost = Entry->Cost [CostKind])
4377
- return adjustTableCost (Entry->ISD , *KindCost, LT.first ,
4378
- ICA.getFlags ());
4382
+ return adjustTableCost (Entry->ISD , *KindCost, LT, ICA.getFlags ());
4379
4383
4380
4384
if (ST->hasSSSE3 ())
4381
4385
if (const auto *Entry = CostTableLookup (SSSE3CostTbl, ISD, MTy))
4382
4386
if (auto KindCost = Entry->Cost [CostKind])
4383
- return adjustTableCost (Entry->ISD , *KindCost, LT.first ,
4384
- ICA.getFlags ());
4387
+ return adjustTableCost (Entry->ISD , *KindCost, LT, ICA.getFlags ());
4385
4388
4386
4389
if (ST->hasSSE2 ())
4387
4390
if (const auto *Entry = CostTableLookup (SSE2CostTbl, ISD, MTy))
4388
4391
if (auto KindCost = Entry->Cost [CostKind])
4389
- return adjustTableCost (Entry->ISD , *KindCost, LT.first ,
4390
- ICA.getFlags ());
4392
+ return adjustTableCost (Entry->ISD , *KindCost, LT, ICA.getFlags ());
4391
4393
4392
4394
if (ST->hasSSE1 ())
4393
4395
if (const auto *Entry = CostTableLookup (SSE1CostTbl, ISD, MTy))
4394
4396
if (auto KindCost = Entry->Cost [CostKind])
4395
- return adjustTableCost (Entry->ISD , *KindCost, LT.first ,
4396
- ICA.getFlags ());
4397
+ return adjustTableCost (Entry->ISD , *KindCost, LT, ICA.getFlags ());
4397
4398
4398
4399
if (ST->hasBMI ()) {
4399
4400
if (ST->is64Bit ())
4400
4401
if (const auto *Entry = CostTableLookup (BMI64CostTbl, ISD, MTy))
4401
4402
if (auto KindCost = Entry->Cost [CostKind])
4402
- return adjustTableCost (Entry->ISD , *KindCost, LT.first ,
4403
- ICA.getFlags ());
4403
+ return adjustTableCost (Entry->ISD , *KindCost, LT, ICA.getFlags ());
4404
4404
4405
4405
if (const auto *Entry = CostTableLookup (BMI32CostTbl, ISD, MTy))
4406
4406
if (auto KindCost = Entry->Cost [CostKind])
4407
- return adjustTableCost (Entry->ISD , *KindCost, LT.first ,
4408
- ICA.getFlags ());
4407
+ return adjustTableCost (Entry->ISD , *KindCost, LT, ICA.getFlags ());
4409
4408
}
4410
4409
4411
4410
if (ST->hasLZCNT ()) {
4412
4411
if (ST->is64Bit ())
4413
4412
if (const auto *Entry = CostTableLookup (LZCNT64CostTbl, ISD, MTy))
4414
4413
if (auto KindCost = Entry->Cost [CostKind])
4415
- return adjustTableCost (Entry->ISD , *KindCost, LT.first ,
4416
- ICA.getFlags ());
4414
+ return adjustTableCost (Entry->ISD , *KindCost, LT, ICA.getFlags ());
4417
4415
4418
4416
if (const auto *Entry = CostTableLookup (LZCNT32CostTbl, ISD, MTy))
4419
4417
if (auto KindCost = Entry->Cost [CostKind])
4420
- return adjustTableCost (Entry->ISD , *KindCost, LT.first ,
4421
- ICA.getFlags ());
4418
+ return adjustTableCost (Entry->ISD , *KindCost, LT, ICA.getFlags ());
4422
4419
}
4423
4420
4424
4421
if (ST->hasPOPCNT ()) {
4425
4422
if (ST->is64Bit ())
4426
4423
if (const auto *Entry = CostTableLookup (POPCNT64CostTbl, ISD, MTy))
4427
4424
if (auto KindCost = Entry->Cost [CostKind])
4428
- return adjustTableCost (Entry->ISD , *KindCost, LT.first ,
4429
- ICA.getFlags ());
4425
+ return adjustTableCost (Entry->ISD , *KindCost, LT, ICA.getFlags ());
4430
4426
4431
4427
if (const auto *Entry = CostTableLookup (POPCNT32CostTbl, ISD, MTy))
4432
4428
if (auto KindCost = Entry->Cost [CostKind])
4433
- return adjustTableCost (Entry->ISD , *KindCost, LT.first ,
4434
- ICA.getFlags ());
4435
- }
4436
-
4437
- if (ISD == ISD::BSWAP && ST->hasMOVBE () && ST->hasFastMOVBE ()) {
4438
- if (const Instruction *II = ICA.getInst ()) {
4439
- if (II->hasOneUse () && isa<StoreInst>(II->user_back ()))
4440
- return TTI::TCC_Free;
4441
- if (auto *LI = dyn_cast<LoadInst>(II->getOperand (0 ))) {
4442
- if (LI->hasOneUse ())
4443
- return TTI::TCC_Free;
4444
- }
4445
- }
4429
+ return adjustTableCost (Entry->ISD , *KindCost, LT, ICA.getFlags ());
4446
4430
}
4447
4431
4448
4432
if (ST->is64Bit ())
4449
4433
if (const auto *Entry = CostTableLookup (X64CostTbl, ISD, MTy))
4450
4434
if (auto KindCost = Entry->Cost [CostKind])
4451
- return adjustTableCost (Entry->ISD , *KindCost, LT.first ,
4452
- ICA.getFlags ());
4435
+ return adjustTableCost (Entry->ISD , *KindCost, LT, ICA.getFlags ());
4453
4436
4454
4437
if (const auto *Entry = CostTableLookup (X86CostTbl, ISD, MTy))
4455
4438
if (auto KindCost = Entry->Cost [CostKind])
4456
- return adjustTableCost (Entry->ISD , *KindCost, LT. first , ICA.getFlags ());
4439
+ return adjustTableCost (Entry->ISD , *KindCost, LT, ICA.getFlags ());
4457
4440
}
4458
4441
4459
4442
return BaseT::getIntrinsicInstrCost (ICA, CostKind);
0 commit comments