18#define DEBUG_TYPE "si-shrink-instructions"
21 "Number of 64-bit instruction reduced to 32-bit.");
23 "Number of literal constants folded into 32-bit instructions.");
29enum ChangeKind {
None, UpdateHint, UpdateInst };
31class SIShrinkInstructions {
32 MachineRegisterInfo *MRI;
33 const GCNSubtarget *ST;
34 const SIInstrInfo *TII;
35 const SIRegisterInfo *TRI;
38 bool foldImmediates(MachineInstr &
MI,
bool TryToCommute =
true)
const;
39 bool shouldShrinkTrue16(MachineInstr &
MI)
const;
40 bool isKImmOperand(
const MachineInstr &
MI,
const MachineOperand &Src)
const;
41 bool isKUImmOperand(
const MachineInstr &
MI,
const MachineOperand &Src)
const;
42 bool isKImmOrKUImmOperand(
const MachineOperand &Src,
bool &IsUnsigned)
const;
43 void copyExtraImplicitOps(MachineInstr &NewMI, MachineInstr &
MI)
const;
44 bool shrinkScalarCompare(MachineInstr &
MI)
const;
45 bool shrinkMIMG(MachineInstr &
MI)
const;
46 bool shrinkMadFma(MachineInstr &
MI)
const;
47 ChangeKind shrinkScalarLogicOp(MachineInstr &
MI)
const;
48 bool tryReplaceDeadSDST(MachineInstr &
MI)
const;
50 unsigned SubReg)
const;
51 bool instReadsReg(
const MachineInstr *
MI,
unsigned Reg,
52 unsigned SubReg)
const;
53 bool instModifiesReg(
const MachineInstr *
MI,
unsigned Reg,
54 unsigned SubReg)
const;
55 TargetInstrInfo::RegSubRegPair getSubRegForIndex(
Register Reg,
unsigned Sub,
57 void dropInstructionKeepingImpDefs(MachineInstr &
MI)
const;
58 MachineInstr *matchSwap(MachineInstr &MovT)
const;
61 SIShrinkInstructions() =
default;
70 SIShrinkInstructionsLegacy() : MachineFunctionPass(ID) {}
74 StringRef getPassName()
const override {
return "SI Shrink Instructions"; }
76 void getAnalysisUsage(AnalysisUsage &AU)
const override {
85 "SI Shrink Instructions",
false,
false)
87char SIShrinkInstructionsLegacy::ID = 0;
90 return new SIShrinkInstructionsLegacy();
97 bool TryToCommute)
const {
100 int Src0Idx = AMDGPU::getNamedOperandIdx(
MI.getOpcode(), AMDGPU::OpName::src0);
103 MachineOperand &
Src0 =
MI.getOperand(Src0Idx);
108 if (Def &&
Def->isMoveImmediate()) {
109 const MachineOperand &MovSrc =
Def->getOperand(1);
110 bool ConstantFolded =
false;
112 if (MovSrc.
isImm()) {
116 if (
TII->isOperandLegal(
MI, Src0Idx, &ImmOp)) {
118 ConstantFolded =
true;
122 if (std::optional<unsigned> Flags =
127 if (
TII->isOperandLegal(
MI, Src0Idx, &GAOp)) {
129 ConstantFolded =
true;
132 }
else if (MovSrc.
isFI() && !
Src0.getSubReg() &&
133 TII->isOperandLegal(
MI, Src0Idx, &MovSrc)) {
135 ConstantFolded =
true;
138 if (ConstantFolded) {
140 Def->eraseFromParent();
141 ++NumLiteralConstantsFolded;
149 if (TryToCommute &&
MI.isCommutable()) {
150 if (
TII->commuteInstruction(
MI)) {
151 if (foldImmediates(
MI,
false))
155 TII->commuteInstruction(
MI);
164bool SIShrinkInstructions::shouldShrinkTrue16(MachineInstr &
MI)
const {
165 for (
unsigned I = 0,
E =
MI.getNumExplicitOperands();
I !=
E; ++
I) {
166 const MachineOperand &MO =
MI.getOperand(
I);
170 "True16 Instructions post-RA");
183bool SIShrinkInstructions::isKImmOperand(
const MachineInstr &
MI,
184 const MachineOperand &Src)
const {
186 !
TII->isInlineConstant(
MI,
MI.getOperandNo(&Src));
189bool SIShrinkInstructions::isKUImmOperand(
const MachineInstr &
MI,
190 const MachineOperand &Src)
const {
192 !
TII->isInlineConstant(
MI,
MI.getOperandNo(&Src));
195bool SIShrinkInstructions::isKImmOrKUImmOperand(
const MachineOperand &Src,
196 bool &IsUnsigned)
const {
199 return !
TII->isInlineConstant(Src);
204 return !
TII->isInlineConstant(Src);
221 int32_t &ModifiedImm,
bool Scalar) {
222 if (
TII->isInlineConstant(Src))
224 int32_t SrcImm =
static_cast<int32_t
>(Src.getImm());
230 ModifiedImm = ~SrcImm;
231 if (
TII->isInlineConstant(
APInt(32, ModifiedImm,
true)))
232 return AMDGPU::V_NOT_B32_e32;
236 if (
TII->isInlineConstant(
APInt(32, ModifiedImm,
true)))
237 return Scalar ? AMDGPU::S_BREV_B32 : AMDGPU::V_BFREV_B32_e32;
244void SIShrinkInstructions::copyExtraImplicitOps(MachineInstr &NewMI,
245 MachineInstr &
MI)
const {
247 for (
unsigned i =
MI.getDesc().getNumOperands() +
248 MI.getDesc().implicit_uses().size() +
249 MI.getDesc().implicit_defs().size(),
250 e =
MI.getNumOperands();
252 const MachineOperand &MO =
MI.getOperand(i);
258bool SIShrinkInstructions::shrinkScalarCompare(MachineInstr &
MI)
const {
265 if (!
MI.getOperand(0).isReg()) {
266 if (
TII->commuteInstruction(
MI,
false, 0, 1))
271 const MachineOperand &
Src0 =
MI.getOperand(0);
275 MachineOperand &
Src1 =
MI.getOperand(1);
285 if (SOPKOpc == AMDGPU::S_CMPK_EQ_U32 || SOPKOpc == AMDGPU::S_CMPK_LG_U32) {
287 if (isKImmOrKUImmOperand(Src1, HasUImm)) {
289 SOPKOpc = (SOPKOpc == AMDGPU::S_CMPK_EQ_U32) ?
290 AMDGPU::S_CMPK_EQ_I32 : AMDGPU::S_CMPK_LG_I32;
294 MI.setDesc(
TII->get(SOPKOpc));
301 const MCInstrDesc &NewDesc =
TII->get(SOPKOpc);
314bool SIShrinkInstructions::shrinkMIMG(MachineInstr &
MI)
const {
320 switch (
Info->MIMGEncoding) {
321 case AMDGPU::MIMGEncGfx10NSA:
322 NewEncoding = AMDGPU::MIMGEncGfx10Default;
324 case AMDGPU::MIMGEncGfx11NSA:
325 NewEncoding = AMDGPU::MIMGEncGfx11Default;
332 AMDGPU::getNamedOperandIdx(
MI.getOpcode(), AMDGPU::OpName::vaddr0);
333 unsigned NewAddrDwords =
Info->VAddrDwords;
336 if (
Info->VAddrDwords == 2) {
337 RC = &AMDGPU::VReg_64RegClass;
338 }
else if (
Info->VAddrDwords == 3) {
339 RC = &AMDGPU::VReg_96RegClass;
340 }
else if (
Info->VAddrDwords == 4) {
341 RC = &AMDGPU::VReg_128RegClass;
342 }
else if (
Info->VAddrDwords == 5) {
343 RC = &AMDGPU::VReg_160RegClass;
344 }
else if (
Info->VAddrDwords == 6) {
345 RC = &AMDGPU::VReg_192RegClass;
346 }
else if (
Info->VAddrDwords == 7) {
347 RC = &AMDGPU::VReg_224RegClass;
348 }
else if (
Info->VAddrDwords == 8) {
349 RC = &AMDGPU::VReg_256RegClass;
350 }
else if (
Info->VAddrDwords == 9) {
351 RC = &AMDGPU::VReg_288RegClass;
352 }
else if (
Info->VAddrDwords == 10) {
353 RC = &AMDGPU::VReg_320RegClass;
354 }
else if (
Info->VAddrDwords == 11) {
355 RC = &AMDGPU::VReg_352RegClass;
356 }
else if (
Info->VAddrDwords == 12) {
357 RC = &AMDGPU::VReg_384RegClass;
359 RC = &AMDGPU::VReg_512RegClass;
363 unsigned VgprBase = 0;
364 unsigned NextVgpr = 0;
366 bool IsKill = NewAddrDwords ==
Info->VAddrDwords;
368 const bool IsPartialNSA = NewAddrDwords > NSAMaxSize;
369 const unsigned EndVAddr = IsPartialNSA ? NSAMaxSize :
Info->VAddrOperands;
370 for (
unsigned Idx = 0;
Idx < EndVAddr; ++
Idx) {
371 const MachineOperand &
Op =
MI.getOperand(VAddr0Idx + Idx);
372 unsigned Vgpr =
TRI->getHWRegIndex(
Op.getReg());
373 unsigned Dwords =
TRI->getRegSizeInBits(
Op.getReg(), *
MRI) / 32;
374 assert(Dwords > 0 &&
"Un-implemented for less than 32 bit regs");
378 NextVgpr = Vgpr + Dwords;
379 }
else if (Vgpr == NextVgpr) {
380 NextVgpr = Vgpr + Dwords;
391 if (VgprBase + NewAddrDwords > 256)
396 int TFEIdx = AMDGPU::getNamedOperandIdx(
MI.getOpcode(), AMDGPU::OpName::tfe);
397 int LWEIdx = AMDGPU::getNamedOperandIdx(
MI.getOpcode(), AMDGPU::OpName::lwe);
398 unsigned TFEVal = (TFEIdx == -1) ? 0 :
MI.getOperand(TFEIdx).
getImm();
401 if (TFEVal || LWEVal) {
403 for (
unsigned i = LWEIdx + 1, e =
MI.getNumOperands(); i != e; ++i) {
404 if (
MI.getOperand(i).isReg() &&
MI.getOperand(i).isTied() &&
405 MI.getOperand(i).isImplicit()) {
409 "found more than one tied implicit operand when expecting only 1");
411 MI.untieRegOperand(ToUntie);
417 Info->VDataDwords, NewAddrDwords);
418 MI.setDesc(
TII->get(NewOpcode));
420 MI.getOperand(VAddr0Idx).setIsUndef(IsUndef);
421 MI.getOperand(VAddr0Idx).setIsKill(IsKill);
423 for (
unsigned i = 1; i < EndVAddr; ++i)
424 MI.removeOperand(VAddr0Idx + 1);
428 AMDGPU::getNamedOperandIdx(
MI.getOpcode(), AMDGPU::OpName::vdata),
429 ToUntie - (EndVAddr - 1));
435bool SIShrinkInstructions::shrinkMadFma(MachineInstr &
MI)
const {
438 if (!ST->hasVOP3Literal())
445 if (
TII->hasAnyModifiersSet(
MI))
448 const unsigned Opcode =
MI.getOpcode();
449 MachineOperand &
Src0 = *
TII->getNamedOperand(
MI, AMDGPU::OpName::src0);
450 MachineOperand &
Src1 = *
TII->getNamedOperand(
MI, AMDGPU::OpName::src1);
451 MachineOperand &
Src2 = *
TII->getNamedOperand(
MI, AMDGPU::OpName::src2);
452 unsigned NewOpcode = AMDGPU::INSTRUCTION_LIST_END;
457 if (
Src2.isImm() && !
TII->isInlineConstant(Src2)) {
468 case AMDGPU::V_MAD_F32_e64:
469 NewOpcode = AMDGPU::V_MADAK_F32;
471 case AMDGPU::V_FMA_F32_e64:
472 NewOpcode = AMDGPU::V_FMAAK_F32;
474 case AMDGPU::V_MAD_F16_e64:
475 NewOpcode = AMDGPU::V_MADAK_F16;
477 case AMDGPU::V_FMA_F16_e64:
478 case AMDGPU::V_FMA_F16_gfx9_e64:
479 NewOpcode = AMDGPU::V_FMAAK_F16;
481 case AMDGPU::V_FMA_F16_gfx9_t16_e64:
482 NewOpcode = AMDGPU::V_FMAAK_F16_t16;
484 case AMDGPU::V_FMA_F16_gfx9_fake16_e64:
485 NewOpcode = AMDGPU::V_FMAAK_F16_fake16;
487 case AMDGPU::V_FMA_F64_e64:
489 NewOpcode = AMDGPU::V_FMAAK_F64;
496 if (
Src1.isImm() && !
TII->isInlineConstant(Src1))
498 else if (
Src0.isImm() && !
TII->isInlineConstant(Src0))
506 case AMDGPU::V_MAD_F32_e64:
507 NewOpcode = AMDGPU::V_MADMK_F32;
509 case AMDGPU::V_FMA_F32_e64:
510 NewOpcode = AMDGPU::V_FMAMK_F32;
512 case AMDGPU::V_MAD_F16_e64:
513 NewOpcode = AMDGPU::V_MADMK_F16;
515 case AMDGPU::V_FMA_F16_e64:
516 case AMDGPU::V_FMA_F16_gfx9_e64:
517 NewOpcode = AMDGPU::V_FMAMK_F16;
519 case AMDGPU::V_FMA_F16_gfx9_t16_e64:
520 NewOpcode = AMDGPU::V_FMAMK_F16_t16;
522 case AMDGPU::V_FMA_F16_gfx9_fake16_e64:
523 NewOpcode = AMDGPU::V_FMAMK_F16_fake16;
525 case AMDGPU::V_FMA_F64_e64:
527 NewOpcode = AMDGPU::V_FMAMK_F64;
532 if (NewOpcode == AMDGPU::INSTRUCTION_LIST_END)
541 MI.getOperand(0).getReg())
546 MI.eraseFromParent();
548 TII->removeModOperands(
MI);
549 MI.setDesc(
TII->get(NewOpcode));
561ChangeKind SIShrinkInstructions::shrinkScalarLogicOp(MachineInstr &
MI)
const {
562 unsigned Opc =
MI.getOpcode();
563 const MachineOperand *Dest = &
MI.getOperand(0);
564 MachineOperand *
Src0 = &
MI.getOperand(1);
565 MachineOperand *
Src1 = &
MI.getOperand(2);
566 MachineOperand *SrcReg =
Src0;
567 MachineOperand *SrcImm =
Src1;
569 if (!SrcImm->
isImm() ||
571 return ChangeKind::None;
573 uint32_t
Imm =
static_cast<uint32_t
>(SrcImm->
getImm());
576 if (
Opc == AMDGPU::S_AND_B32) {
578 MI.findRegisterDefOperand(AMDGPU::SCC,
nullptr)->isDead()) {
580 Opc = AMDGPU::S_BITSET0_B32;
583 Opc = AMDGPU::S_ANDN2_B32;
585 }
else if (
Opc == AMDGPU::S_OR_B32) {
587 MI.findRegisterDefOperand(AMDGPU::SCC,
nullptr)->isDead()) {
589 Opc = AMDGPU::S_BITSET1_B32;
592 Opc = AMDGPU::S_ORN2_B32;
594 }
else if (
Opc == AMDGPU::S_XOR_B32) {
597 Opc = AMDGPU::S_XNOR_B32;
607 return ChangeKind::UpdateHint;
611 const bool IsUndef = SrcReg->
isUndef();
612 const bool IsKill = SrcReg->
isKill();
614 if (
Opc == AMDGPU::S_BITSET0_B32 ||
615 Opc == AMDGPU::S_BITSET1_B32) {
616 Src0->ChangeToImmediate(NewImm);
618 MI.getOperand(2).ChangeToRegister(Dest->
getReg(),
false,
621 MI.tieOperands(0, 2);
625 return ChangeKind::UpdateInst;
629 return ChangeKind::None;
634bool SIShrinkInstructions::instAccessReg(
636 unsigned SubReg)
const {
637 for (
const MachineOperand &MO : R) {
642 LaneBitmask Overlap =
TRI->getSubRegIndexLaneMask(SubReg) &
651bool SIShrinkInstructions::instReadsReg(
const MachineInstr *
MI,
unsigned Reg,
652 unsigned SubReg)
const {
653 return instAccessReg(
MI->all_uses(),
Reg, SubReg);
656bool SIShrinkInstructions::instModifiesReg(
const MachineInstr *
MI,
unsigned Reg,
657 unsigned SubReg)
const {
658 return instAccessReg(
MI->all_defs(),
Reg, SubReg);
661TargetInstrInfo::RegSubRegPair
662SIShrinkInstructions::getSubRegForIndex(
Register Reg,
unsigned Sub,
664 if (
TRI->getRegSizeInBits(
Reg, *
MRI) != 32) {
668 Sub =
TRI->getSubRegFromChannel(
I +
TRI->getChannelFromSubReg(
Sub));
671 return TargetInstrInfo::RegSubRegPair(
Reg,
Sub);
674void SIShrinkInstructions::dropInstructionKeepingImpDefs(
675 MachineInstr &
MI)
const {
676 for (
unsigned i =
MI.getDesc().getNumOperands() +
677 MI.getDesc().implicit_uses().size() +
678 MI.getDesc().implicit_defs().size(),
679 e =
MI.getNumOperands();
681 const MachineOperand &
Op =
MI.getOperand(i);
685 TII->get(AMDGPU::IMPLICIT_DEF),
Op.getReg());
688 MI.eraseFromParent();
710MachineInstr *SIShrinkInstructions::matchSwap(MachineInstr &MovT)
const {
712 MovT.
getOpcode() == AMDGPU::V_MOV_B16_t16_e32 ||
726 unsigned Size =
TII->getOpSize(MovT, 0);
730 if (
Size == 2 &&
X.isVirtual())
736 const unsigned SearchLimit = 16;
739 MachineInstr *MovX =
nullptr;
740 MachineInstr *InsertionPt =
nullptr;
741 MachineInstr *MovY =
nullptr;
745 Iter !=
E &&
Count < SearchLimit; ++Iter) {
746 if (Iter->isDebugInstr())
752 if ((Iter->getOpcode() == AMDGPU::V_MOV_B32_e32 ||
753 Iter->getOpcode() == AMDGPU::V_MOV_B16_t16_e32 ||
754 Iter->getOpcode() == AMDGPU::COPY) &&
755 Iter->getOperand(0).getReg() ==
X &&
756 Iter->getOperand(0).getSubReg() == Xsub &&
757 Iter->getOperand(1).isReg()) {
761 }
else if (instModifiesReg(&*Iter,
X, Xsub)) {
768 if ((Iter->getOpcode() == AMDGPU::V_MOV_B32_e32 ||
769 Iter->getOpcode() == AMDGPU::V_MOV_B16_t16_e32 ||
770 Iter->getOpcode() == AMDGPU::COPY) &&
771 Iter->getOperand(0).getReg() ==
Y &&
772 Iter->getOperand(0).getSubReg() == Ysub &&
773 Iter->getOperand(1).isReg() && Iter->getOperand(1).getReg() ==
T &&
774 Iter->getOperand(1).getSubReg() == Tsub) {
783 if (instModifiesReg(&*Iter,
Y, Ysub))
789 (instReadsReg(&*Iter,
X, Xsub) || instModifiesReg(&*Iter,
X, Xsub))) {
790 InsertionPt = &*Iter;
796 if (instReadsReg(&*Iter,
Y, Ysub))
801 if (instModifiesReg(&*Iter,
T, Tsub))
805 LLVM_DEBUG(
dbgs() <<
"Matched v_swap:\n" << MovT << *MovX << *MovY);
808 SmallVector<MachineInstr *, 4> Swaps;
814 TII->get(AMDGPU::V_SWAP_B16))
823 for (
unsigned I = 0;
I <
Size / 4; ++
I) {
824 TargetInstrInfo::RegSubRegPair X1, Y1;
825 X1 = getSubRegForIndex(
X, Xsub,
I);
826 Y1 = getSubRegForIndex(
Y, Ysub,
I);
828 TII->get(AMDGPU::V_SWAP_B32))
839 for (MachineInstr *
Swap : Swaps) {
840 Swap->removeOperand(
Swap->getNumExplicitOperands());
845 dropInstructionKeepingImpDefs(*MovY);
849 dropInstructionKeepingImpDefs(MovT);
855 if (
Op.isKill() &&
TRI->regsOverlap(
X,
Op.getReg()))
866bool SIShrinkInstructions::tryReplaceDeadSDST(MachineInstr &
MI)
const {
867 if (!ST->hasGFX10_3Insts())
870 MachineOperand *
Op =
TII->getNamedOperand(
MI, AMDGPU::OpName::sdst);
877 Op->setReg(ST->
isWave32() ? AMDGPU::SGPR_NULL : AMDGPU::SGPR_NULL64);
888 unsigned VCCReg = ST->
isWave32() ? AMDGPU::VCC_LO : AMDGPU::VCC;
891 for (MachineBasicBlock &
MBB : MF) {
895 MachineInstr &
MI = *
I;
897 if (
MI.getOpcode() == AMDGPU::V_MOV_B32_e32) {
905 MachineOperand &Src =
MI.getOperand(1);
906 if (Src.isImm() && IsPostRA) {
910 if (ModOpcode != 0) {
911 MI.setDesc(
TII->get(ModOpcode));
912 Src.setImm(
static_cast<int64_t
>(ModImm));
919 if (ST->
hasSwap() && (
MI.getOpcode() == AMDGPU::V_MOV_B32_e32 ||
920 MI.getOpcode() == AMDGPU::V_MOV_B16_t16_e32 ||
921 MI.getOpcode() == AMDGPU::COPY)) {
922 if (
auto *NextMI = matchSwap(
MI)) {
923 Next = NextMI->getIterator();
930 if (
MI.getOpcode() == AMDGPU::S_AND_B32 ||
931 MI.getOpcode() == AMDGPU::S_OR_B32 ||
932 MI.getOpcode() == AMDGPU::S_XOR_B32) {
933 ChangeKind CK = shrinkScalarLogicOp(
MI);
934 if (CK == ChangeKind::UpdateHint)
936 Changed |= (CK == ChangeKind::UpdateInst);
942 if (
MI.getOpcode() == AMDGPU::S_ADD_I32 ||
943 MI.getOpcode() == AMDGPU::S_MUL_I32 ||
944 (
MI.getOpcode() == AMDGPU::S_OR_B32 &&
945 MI.getFlag(MachineInstr::MIFlag::Disjoint) &&
946 MI.allImplicitDefsAreDead())) {
947 const MachineOperand *Dest = &
MI.getOperand(0);
948 MachineOperand *
Src0 = &
MI.getOperand(1);
949 MachineOperand *
Src1 = &
MI.getOperand(2);
951 if (!
Src0->isReg() &&
Src1->isReg()) {
952 if (
TII->commuteInstruction(
MI,
false, 1, 2)) {
968 unsigned Opc = (
MI.getOpcode() == AMDGPU::S_MUL_I32)
970 : AMDGPU::S_ADDK_I32;
973 MI.tieOperands(0, 1);
980 if (
MI.isCompare() &&
TII->isSOPC(
MI)) {
986 if (
MI.getOpcode() == AMDGPU::S_MOV_B32) {
987 const MachineOperand &Dst =
MI.getOperand(0);
988 MachineOperand &Src =
MI.getOperand(1);
990 if (Src.isImm() && Dst.getReg().isPhysical()) {
994 MI.setDesc(
TII->get(AMDGPU::S_MOVK_I32));
999 MI.setDesc(
TII->get(ModOpc));
1000 Src.setImm(
static_cast<int64_t
>(ModImm));
1008 if (IsPostRA &&
TII->isMIMG(
MI.getOpcode()) &&
1014 if (!
TII->isVOP3(
MI))
1017 if (
MI.getOpcode() == AMDGPU::V_MAD_F32_e64 ||
1018 MI.getOpcode() == AMDGPU::V_FMA_F32_e64 ||
1019 MI.getOpcode() == AMDGPU::V_MAD_F16_e64 ||
1020 MI.getOpcode() == AMDGPU::V_FMA_F16_e64 ||
1021 MI.getOpcode() == AMDGPU::V_FMA_F16_gfx9_e64 ||
1022 MI.getOpcode() == AMDGPU::V_FMA_F16_gfx9_t16_e64 ||
1023 MI.getOpcode() == AMDGPU::V_FMA_F16_gfx9_fake16_e64 ||
1024 (
MI.getOpcode() == AMDGPU::V_FMA_F64_e64 &&
1033 if (!
TII->hasVALU32BitEncoding(
MI.getOpcode()))
1039 if (!
MI.isCommutable() || !
TII->commuteInstruction(
MI) ||
1051 if (Op32 == AMDGPU::V_CNDMASK_B32_e32) {
1054 const MachineOperand *
Src2 =
1055 TII->getNamedOperand(
MI, AMDGPU::OpName::src2);
1059 if (
SReg.isVirtual()) {
1070 const MachineOperand *SDst =
1071 TII->getNamedOperand(
MI, AMDGPU::OpName::sdst);
1076 if (SDst->
getReg() != VCCReg) {
1093 const MachineOperand *
Src2 =
TII->getNamedOperand(
MI,
1094 AMDGPU::OpName::src2);
1095 if (Src2 &&
Src2->getReg() != VCCReg) {
1096 if (
Src2->getReg().isVirtual())
1111 if (ST->hasVOP3Literal() &&
1117 !shouldShrinkTrue16(
MI))
1123 MachineInstr *Inst32 =
TII->buildShrunkInst(
MI, Op32);
1124 ++NumInstructionsShrunk;
1127 copyExtraImplicitOps(*Inst32,
MI);
1129 MI.eraseFromParent();
1130 foldImmediates(*Inst32);
1139bool SIShrinkInstructionsLegacy::runOnMachineFunction(
MachineFunction &MF) {
1143 return SIShrinkInstructions().run(MF);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
AMD GCN specific subclass of TargetSubtarget.
const HexagonInstrInfo * TII
Register const TargetRegisterInfo * TRI
Promote Memory to Register
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
MachineRegisterInfo & MRI
static unsigned canModifyToInlineImmOp32(const SIInstrInfo *TII, const MachineOperand &Src, int32_t &ModifiedImm, bool Scalar)
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
Class for arbitrary precision integers.
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Represents analyses that only rely on functions' control flow.
FunctionPass class - This class is used to implement most global optimizations.
bool hasOptNone() const
Do not optimize this function (-O0).
bool hasFmaakFmamkF64Insts() const
const SIInstrInfo * getInstrInfo() const override
unsigned getNSAMaxSize(bool HasSampler=false) const
Generation getGeneration() const
const HexagonRegisterInfo & getRegisterInfo() const
MCRegister getRegister(unsigned i) const
getRegister - Return the specified register in the class.
instr_iterator instr_end()
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
MachineInstrBundleIterator< MachineInstr > iterator
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineFunctionProperties & getProperties() const
Get the function properties.
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & addDef(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register definition operand.
const MachineInstrBuilder & setMIFlags(unsigned Flags) const
MachineInstr * getInstr() const
If conversion operators fail, use this method to get the MachineInstr explicitly.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
unsigned getNumImplicitOperands() const
Returns the implicit operands number.
iterator_range< filter_iterator< const_mop_iterator, bool(*)(const MachineOperand &)> > filtered_const_mop_range
const MachineBasicBlock * getParent() const
LLVM_ABI void addOperand(MachineFunction &MF, const MachineOperand &Op)
Add the specified operand to the instruction.
LLVM_ABI unsigned getNumExplicitOperands() const
Returns the number of non-implicit operands.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
LLVM_ABI void removeOperand(unsigned OpNo)
Erase an operand from an instruction, leaving it with one fewer operand than it started with.
const MachineOperand & getOperand(unsigned i) const
LLVM_ABI bool hasRegisterImplicitUseOperand(Register Reg) const
Returns true if the MachineInstr has an implicit-use operand of exactly the given register (not consi...
LLVM_ABI MachineInstrBundleIterator< MachineInstr > eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
MachineOperand class - Representation of each machine instruction operand.
unsigned getSubReg() const
const GlobalValue * getGlobal() const
void setImm(int64_t immVal)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
bool isRegMask() const
isRegMask - Tests if this is a MO_RegisterMask operand.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
void setIsKill(bool Val=true)
unsigned getTargetFlags() const
static MachineOperand CreateImm(int64_t Val)
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
Register getReg() const
getReg - Returns the register number.
static MachineOperand CreateGA(const GlobalValue *GV, int64_t Offset, unsigned TargetFlags=0)
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
int64_t getOffset() const
Return the offset from the symbol in this operand.
bool use_nodbg_empty(Register RegNo) const
use_nodbg_empty - Return true if there are no non-Debug instructions using the specified register.
void setRegAllocationHint(Register VReg, unsigned Type, Register PrefReg)
setRegAllocationHint - Specify a register allocation hint for the specified virtual register.
LLVM_ABI LLVM_READONLY MachineInstr * getUniqueVRegDef(Register Reg) const
getUniqueVRegDef - Return the unique machine instr that defines the specified virtual register or nul...
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
static std::optional< unsigned > extractSubregFromGlobalAddressFlags(unsigned TargetFlags, unsigned SubRegIndex)
Return the target flags for a global address operand reading subregister SubRegIndex of a 64-bit glob...
static std::optional< int64_t > extractSubregFromImm(int64_t ImmVal, unsigned SubRegIndex)
Return the extracted immediate value in a subregister use from a constant materialized in a super reg...
static bool sopkIsZext(unsigned Opcode)
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &)
void push_back(const T &Elt)
self_iterator getIterator()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_READONLY const MIMGInfo * getMIMGInfo(unsigned Opc)
LLVM_READONLY int32_t getSOPKOp(uint32_t Opcode)
bool isKImmOperand(const MCInstrDesc &Desc, unsigned OpNo)
Is this a KImm operand?
int getMIMGOpcode(unsigned BaseOpcode, unsigned MIMGEncoding, unsigned VDataDwords, unsigned VAddrDwords, bool IndexedRsrc, bool IndexedSamp)
bool isTrue16Inst(unsigned Opc)
bool isInlinableLiteral32(int32_t Literal, bool HasInv2Pi)
LLVM_READONLY int32_t getVOPe32(uint32_t Opcode)
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
NodeAddr< DefNode * > Def
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
int countr_one(T Value)
Count the number of ones from the least significant bit to the first zero bit.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
@ Sub
Subtraction of integers.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
DWARFExpression::Operation Op
constexpr int32_t SignExtend32(uint32_t X)
Sign-extend the number in the bottom B bits of X to a 32-bit integer.
constexpr T reverseBits(T Val)
Reverse the bits in Val.
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next
FunctionPass * createSIShrinkInstructionsLegacyPass()
MCRegisterClass TargetRegisterClass
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
constexpr bool any() const