@@ -226,6 +226,7 @@ static Constant *rebuildConstant(LLVMContext &Ctx, Type *SclTy,
226
226
// width, built up of potentially smaller scalar values.
227
227
static Constant *rebuildSplatCst (const Constant *C, unsigned /* NumBits*/ ,
228
228
unsigned /* NumElts*/ , unsigned SplatBitWidth) {
229
+ // TODO: Truncate to NumBits once ConvertToBroadcastAVX512 support this.
229
230
std::optional<APInt> Splat = getSplatableConstant (C, SplatBitWidth);
230
231
if (!Splat)
231
232
return nullptr ;
@@ -328,7 +329,8 @@ bool X86FixupVectorConstantsPass::processInstruction(MachineFunction &MF,
328
329
std::function<Constant *(const Constant *, unsigned , unsigned , unsigned )>
329
330
RebuildConstant;
330
331
};
331
- auto FixupConstant = [&](ArrayRef<FixupEntry> Fixups, unsigned OperandNo) {
332
+ auto FixupConstant = [&](ArrayRef<FixupEntry> Fixups, unsigned RegBitWidth,
333
+ unsigned OperandNo) {
332
334
#ifdef EXPENSIVE_CHECKS
333
335
assert (llvm::is_sorted (Fixups,
334
336
[](const FixupEntry &A, const FixupEntry &B) {
@@ -340,7 +342,8 @@ bool X86FixupVectorConstantsPass::processInstruction(MachineFunction &MF,
340
342
assert (MI.getNumOperands () >= (OperandNo + X86::AddrNumOperands) &&
341
343
" Unexpected number of operands!" );
342
344
if (auto *C = X86::getConstantFromPool (MI, OperandNo)) {
343
- unsigned RegBitWidth = C->getType ()->getPrimitiveSizeInBits ();
345
+ RegBitWidth =
346
+ RegBitWidth ? RegBitWidth : C->getType ()->getPrimitiveSizeInBits ();
344
347
for (const FixupEntry &Fixup : Fixups) {
345
348
if (Fixup.Op ) {
346
349
// Construct a suitable constant and adjust the MI to use the new
@@ -377,7 +380,7 @@ bool X86FixupVectorConstantsPass::processInstruction(MachineFunction &MF,
377
380
// TODO: SSE3 MOVDDUP Handling
378
381
return FixupConstant ({{X86::MOVSSrm, 1 , 32 , rebuildZeroUpperCst},
379
382
{X86::MOVSDrm, 1 , 64 , rebuildZeroUpperCst}},
380
- 1 );
383
+ 128 , 1 );
381
384
case X86::VMOVAPDrm:
382
385
case X86::VMOVAPSrm:
383
386
case X86::VMOVUPDrm:
@@ -386,15 +389,15 @@ bool X86FixupVectorConstantsPass::processInstruction(MachineFunction &MF,
386
389
{X86::VBROADCASTSSrm, 1 , 32 , rebuildSplatCst},
387
390
{X86::VMOVSDrm, 1 , 64 , rebuildZeroUpperCst},
388
391
{X86::VMOVDDUPrm, 1 , 64 , rebuildSplatCst}},
389
- 1 );
392
+ 128 , 1 );
390
393
case X86::VMOVAPDYrm:
391
394
case X86::VMOVAPSYrm:
392
395
case X86::VMOVUPDYrm:
393
396
case X86::VMOVUPSYrm:
394
397
return FixupConstant ({{X86::VBROADCASTSSYrm, 1 , 32 , rebuildSplatCst},
395
398
{X86::VBROADCASTSDYrm, 1 , 64 , rebuildSplatCst},
396
399
{X86::VBROADCASTF128rm, 1 , 128 , rebuildSplatCst}},
397
- 1 );
400
+ 256 , 1 );
398
401
case X86::VMOVAPDZ128rm:
399
402
case X86::VMOVAPSZ128rm:
400
403
case X86::VMOVUPDZ128rm:
@@ -403,7 +406,7 @@ bool X86FixupVectorConstantsPass::processInstruction(MachineFunction &MF,
403
406
{X86::VBROADCASTSSZ128rm, 1 , 32 , rebuildSplatCst},
404
407
{X86::VMOVSDZrm, 1 , 64 , rebuildZeroUpperCst},
405
408
{X86::VMOVDDUPZ128rm, 1 , 64 , rebuildSplatCst}},
406
- 1 );
409
+ 128 , 1 );
407
410
case X86::VMOVAPDZ256rm:
408
411
case X86::VMOVAPSZ256rm:
409
412
case X86::VMOVUPDZ256rm:
@@ -412,7 +415,7 @@ bool X86FixupVectorConstantsPass::processInstruction(MachineFunction &MF,
412
415
{{X86::VBROADCASTSSZ256rm, 1 , 32 , rebuildSplatCst},
413
416
{X86::VBROADCASTSDZ256rm, 1 , 64 , rebuildSplatCst},
414
417
{X86::VBROADCASTF32X4Z256rm, 1 , 128 , rebuildSplatCst}},
415
- 1 );
418
+ 256 , 1 );
416
419
case X86::VMOVAPDZrm:
417
420
case X86::VMOVAPSZrm:
418
421
case X86::VMOVUPDZrm:
@@ -421,7 +424,7 @@ bool X86FixupVectorConstantsPass::processInstruction(MachineFunction &MF,
421
424
{X86::VBROADCASTSDZrm, 1 , 64 , rebuildSplatCst},
422
425
{X86::VBROADCASTF32X4rm, 1 , 128 , rebuildSplatCst},
423
426
{X86::VBROADCASTF64X4rm, 1 , 256 , rebuildSplatCst}},
424
- 1 );
427
+ 512 , 1 );
425
428
/* Integer Loads */
426
429
case X86::MOVDQArm:
427
430
case X86::MOVDQUrm: {
@@ -440,7 +443,7 @@ bool X86FixupVectorConstantsPass::processInstruction(MachineFunction &MF,
440
443
{HasSSE41 ? X86::PMOVZXWDrm : 0 , 4 , 16 , rebuildZExtCst},
441
444
{HasSSE41 ? X86::PMOVSXDQrm : 0 , 2 , 32 , rebuildSExtCst},
442
445
{HasSSE41 ? X86::PMOVZXDQrm : 0 , 2 , 32 , rebuildZExtCst}};
443
- return FixupConstant (Fixups, 1 );
446
+ return FixupConstant (Fixups, 128 , 1 );
444
447
}
445
448
case X86::VMOVDQArm:
446
449
case X86::VMOVDQUrm: {
@@ -465,7 +468,7 @@ bool X86FixupVectorConstantsPass::processInstruction(MachineFunction &MF,
465
468
{X86::VPMOVZXWDrm, 4 , 16 , rebuildZExtCst},
466
469
{X86::VPMOVSXDQrm, 2 , 32 , rebuildSExtCst},
467
470
{X86::VPMOVZXDQrm, 2 , 32 , rebuildZExtCst}};
468
- return FixupConstant (Fixups, 1 );
471
+ return FixupConstant (Fixups, 128 , 1 );
469
472
}
470
473
case X86::VMOVDQAYrm:
471
474
case X86::VMOVDQUYrm: {
@@ -490,7 +493,7 @@ bool X86FixupVectorConstantsPass::processInstruction(MachineFunction &MF,
490
493
{HasAVX2 ? X86::VPMOVZXWDYrm : 0 , 8 , 16 , rebuildZExtCst},
491
494
{HasAVX2 ? X86::VPMOVSXDQYrm : 0 , 4 , 32 , rebuildSExtCst},
492
495
{HasAVX2 ? X86::VPMOVZXDQYrm : 0 , 4 , 32 , rebuildZExtCst}};
493
- return FixupConstant (Fixups, 1 );
496
+ return FixupConstant (Fixups, 256 , 1 );
494
497
}
495
498
case X86::VMOVDQA32Z128rm:
496
499
case X86::VMOVDQA64Z128rm:
@@ -515,7 +518,7 @@ bool X86FixupVectorConstantsPass::processInstruction(MachineFunction &MF,
515
518
{X86::VPMOVZXWDZ128rm, 4 , 16 , rebuildZExtCst},
516
519
{X86::VPMOVSXDQZ128rm, 2 , 32 , rebuildSExtCst},
517
520
{X86::VPMOVZXDQZ128rm, 2 , 32 , rebuildZExtCst}};
518
- return FixupConstant (Fixups, 1 );
521
+ return FixupConstant (Fixups, 128 , 1 );
519
522
}
520
523
case X86::VMOVDQA32Z256rm:
521
524
case X86::VMOVDQA64Z256rm:
@@ -539,7 +542,7 @@ bool X86FixupVectorConstantsPass::processInstruction(MachineFunction &MF,
539
542
{X86::VPMOVZXWDZ256rm, 8 , 16 , rebuildZExtCst},
540
543
{X86::VPMOVSXDQZ256rm, 4 , 32 , rebuildSExtCst},
541
544
{X86::VPMOVZXDQZ256rm, 4 , 32 , rebuildZExtCst}};
542
- return FixupConstant (Fixups, 1 );
545
+ return FixupConstant (Fixups, 256 , 1 );
543
546
}
544
547
case X86::VMOVDQA32Zrm:
545
548
case X86::VMOVDQA64Zrm:
@@ -564,7 +567,7 @@ bool X86FixupVectorConstantsPass::processInstruction(MachineFunction &MF,
564
567
{X86::VPMOVZXWDZrm, 16 , 16 , rebuildZExtCst},
565
568
{X86::VPMOVSXDQZrm, 8 , 32 , rebuildSExtCst},
566
569
{X86::VPMOVZXDQZrm, 8 , 32 , rebuildZExtCst}};
567
- return FixupConstant (Fixups, 1 );
570
+ return FixupConstant (Fixups, 512 , 1 );
568
571
}
569
572
}
570
573
@@ -592,7 +595,9 @@ bool X86FixupVectorConstantsPass::processInstruction(MachineFunction &MF,
592
595
unsigned OpNo = OpBcst32 == 0 ? OpNoBcst64 : OpNoBcst32;
593
596
FixupEntry Fixups[] = {{(int )OpBcst32, 32 , 32 , rebuildSplatCst},
594
597
{(int )OpBcst64, 64 , 64 , rebuildSplatCst}};
595
- return FixupConstant (Fixups, OpNo);
598
+ // TODO: Add support for RegBitWidth, but currently rebuildSplatCst
599
+ // doesn't require it (defaults to Constant::getPrimitiveSizeInBits).
600
+ return FixupConstant (Fixups, 0 , OpNo);
596
601
}
597
602
return false ;
598
603
};
0 commit comments