xref: /llvm-project/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp (revision 8485fa096e0baf95790a8b1ba7f8ea8806f50a3e)
1 //===-- SIFoldOperands.cpp - Fold operands --- ----------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 /// \file
9 //===----------------------------------------------------------------------===//
10 //
11 
12 #include "AMDGPU.h"
13 #include "AMDGPUSubtarget.h"
14 #include "SIInstrInfo.h"
15 #include "llvm/CodeGen/LiveIntervalAnalysis.h"
16 #include "llvm/CodeGen/MachineFunctionPass.h"
17 #include "llvm/CodeGen/MachineInstrBuilder.h"
18 #include "llvm/CodeGen/MachineRegisterInfo.h"
19 #include "llvm/Support/Debug.h"
20 #include "llvm/Support/raw_ostream.h"
21 #include "llvm/Target/TargetMachine.h"
22 
23 #define DEBUG_TYPE "si-fold-operands"
24 using namespace llvm;
25 
26 namespace {
27 
28 class SIFoldOperands : public MachineFunctionPass {
29 public:
30   static char ID;
31 
32 public:
33   SIFoldOperands() : MachineFunctionPass(ID) {
34     initializeSIFoldOperandsPass(*PassRegistry::getPassRegistry());
35   }
36 
37   bool runOnMachineFunction(MachineFunction &MF) override;
38 
39   StringRef getPassName() const override { return "SI Fold Operands"; }
40 
41   void getAnalysisUsage(AnalysisUsage &AU) const override {
42     AU.setPreservesCFG();
43     MachineFunctionPass::getAnalysisUsage(AU);
44   }
45 };
46 
47 struct FoldCandidate {
48   MachineInstr *UseMI;
49   union {
50     MachineOperand *OpToFold;
51     uint64_t ImmToFold;
52     int FrameIndexToFold;
53   };
54   unsigned char UseOpNo;
55   MachineOperand::MachineOperandType Kind;
56 
57   FoldCandidate(MachineInstr *MI, unsigned OpNo, MachineOperand *FoldOp) :
58     UseMI(MI), OpToFold(nullptr), UseOpNo(OpNo), Kind(FoldOp->getType()) {
59     if (FoldOp->isImm()) {
60       ImmToFold = FoldOp->getImm();
61     } else if (FoldOp->isFI()) {
62       FrameIndexToFold = FoldOp->getIndex();
63     } else {
64       assert(FoldOp->isReg());
65       OpToFold = FoldOp;
66     }
67   }
68 
69   bool isFI() const {
70     return Kind == MachineOperand::MO_FrameIndex;
71   }
72 
73   bool isImm() const {
74     return Kind == MachineOperand::MO_Immediate;
75   }
76 
77   bool isReg() const {
78     return Kind == MachineOperand::MO_Register;
79   }
80 };
81 
82 } // End anonymous namespace.
83 
84 INITIALIZE_PASS(SIFoldOperands, DEBUG_TYPE,
85                 "SI Fold Operands", false, false)
86 
87 char SIFoldOperands::ID = 0;
88 
89 char &llvm::SIFoldOperandsID = SIFoldOperands::ID;
90 
91 FunctionPass *llvm::createSIFoldOperandsPass() {
92   return new SIFoldOperands();
93 }
94 
95 static bool isSafeToFold(const MachineInstr &MI) {
96   switch (MI.getOpcode()) {
97   case AMDGPU::V_MOV_B32_e32:
98   case AMDGPU::V_MOV_B32_e64:
99   case AMDGPU::V_MOV_B64_PSEUDO: {
100     // If there are additional implicit register operands, this may be used for
101     // register indexing so the source register operand isn't simply copied.
102     unsigned NumOps = MI.getDesc().getNumOperands() +
103       MI.getDesc().getNumImplicitUses();
104 
105     return MI.getNumOperands() == NumOps;
106   }
107   case AMDGPU::S_MOV_B32:
108   case AMDGPU::S_MOV_B64:
109   case AMDGPU::COPY:
110     return true;
111   default:
112     return false;
113   }
114 }
115 
116 static bool updateOperand(FoldCandidate &Fold,
117                           const TargetRegisterInfo &TRI) {
118   MachineInstr *MI = Fold.UseMI;
119   MachineOperand &Old = MI->getOperand(Fold.UseOpNo);
120   assert(Old.isReg());
121 
122   if (Fold.isImm()) {
123     Old.ChangeToImmediate(Fold.ImmToFold);
124     return true;
125   }
126 
127   if (Fold.isFI()) {
128     Old.ChangeToFrameIndex(Fold.FrameIndexToFold);
129     return true;
130   }
131 
132   MachineOperand *New = Fold.OpToFold;
133   if (TargetRegisterInfo::isVirtualRegister(Old.getReg()) &&
134       TargetRegisterInfo::isVirtualRegister(New->getReg())) {
135     Old.substVirtReg(New->getReg(), New->getSubReg(), TRI);
136     return true;
137   }
138 
139   // FIXME: Handle physical registers.
140 
141   return false;
142 }
143 
144 static bool isUseMIInFoldList(const std::vector<FoldCandidate> &FoldList,
145                               const MachineInstr *MI) {
146   for (auto Candidate : FoldList) {
147     if (Candidate.UseMI == MI)
148       return true;
149   }
150   return false;
151 }
152 
153 static bool tryAddToFoldList(std::vector<FoldCandidate> &FoldList,
154                              MachineInstr *MI, unsigned OpNo,
155                              MachineOperand *OpToFold,
156                              const SIInstrInfo *TII) {
157   if (!TII->isOperandLegal(*MI, OpNo, OpToFold)) {
158 
159     // Special case for v_mac_{f16, f32}_e64 if we are trying to fold into src2
160     unsigned Opc = MI->getOpcode();
161     if ((Opc == AMDGPU::V_MAC_F32_e64 || Opc == AMDGPU::V_MAC_F16_e64) &&
162         (int)OpNo == AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::src2)) {
163       bool IsF32  = Opc == AMDGPU::V_MAC_F32_e64;
164 
165       // Check if changing this to a v_mad_{f16, f32} instruction will allow us
166       // to fold the operand.
167       MI->setDesc(TII->get(IsF32 ? AMDGPU::V_MAD_F32 : AMDGPU::V_MAD_F16));
168       bool FoldAsMAD = tryAddToFoldList(FoldList, MI, OpNo, OpToFold, TII);
169       if (FoldAsMAD) {
170         MI->untieRegOperand(OpNo);
171         return true;
172       }
173       MI->setDesc(TII->get(Opc));
174     }
175 
176     // Special case for s_setreg_b32
177     if (Opc == AMDGPU::S_SETREG_B32 && OpToFold->isImm()) {
178       MI->setDesc(TII->get(AMDGPU::S_SETREG_IMM32_B32));
179       FoldList.push_back(FoldCandidate(MI, OpNo, OpToFold));
180       return true;
181     }
182 
183     // If we are already folding into another operand of MI, then
184     // we can't commute the instruction, otherwise we risk making the
185     // other fold illegal.
186     if (isUseMIInFoldList(FoldList, MI))
187       return false;
188 
189     // Operand is not legal, so try to commute the instruction to
190     // see if this makes it possible to fold.
191     unsigned CommuteIdx0 = TargetInstrInfo::CommuteAnyOperandIndex;
192     unsigned CommuteIdx1 = TargetInstrInfo::CommuteAnyOperandIndex;
193     bool CanCommute = TII->findCommutedOpIndices(*MI, CommuteIdx0, CommuteIdx1);
194 
195     if (CanCommute) {
196       if (CommuteIdx0 == OpNo)
197         OpNo = CommuteIdx1;
198       else if (CommuteIdx1 == OpNo)
199         OpNo = CommuteIdx0;
200     }
201 
202     // One of operands might be an Imm operand, and OpNo may refer to it after
203     // the call of commuteInstruction() below. Such situations are avoided
204     // here explicitly as OpNo must be a register operand to be a candidate
205     // for memory folding.
206     if (CanCommute && (!MI->getOperand(CommuteIdx0).isReg() ||
207                        !MI->getOperand(CommuteIdx1).isReg()))
208       return false;
209 
210     if (!CanCommute ||
211         !TII->commuteInstruction(*MI, false, CommuteIdx0, CommuteIdx1))
212       return false;
213 
214     if (!TII->isOperandLegal(*MI, OpNo, OpToFold))
215       return false;
216   }
217 
218   FoldList.push_back(FoldCandidate(MI, OpNo, OpToFold));
219   return true;
220 }
221 
222 // If the use operand doesn't care about the value, this may be an operand only
223 // used for register indexing, in which case it is unsafe to fold.
224 static bool isUseSafeToFold(const MachineInstr &MI,
225                             const MachineOperand &UseMO) {
226   return !UseMO.isUndef();
227   //return !MI.hasRegisterImplicitUseOperand(UseMO.getReg());
228 }
229 
230 static void foldOperand(MachineOperand &OpToFold, MachineInstr *UseMI,
231                         unsigned UseOpIdx,
232                         std::vector<FoldCandidate> &FoldList,
233                         SmallVectorImpl<MachineInstr *> &CopiesToReplace,
234                         const SIInstrInfo *TII, const SIRegisterInfo &TRI,
235                         MachineRegisterInfo &MRI) {
236   const MachineOperand &UseOp = UseMI->getOperand(UseOpIdx);
237 
238   if (!isUseSafeToFold(*UseMI, UseOp))
239     return;
240 
241   // FIXME: Fold operands with subregs.
242   if (UseOp.isReg() && OpToFold.isReg()) {
243     if (UseOp.isImplicit() || UseOp.getSubReg() != AMDGPU::NoSubRegister)
244       return;
245 
246     // Don't fold subregister extracts into tied operands, only if it is a full
247     // copy since a subregister use tied to a full register def doesn't really
248     // make sense. e.g. don't fold:
249     //
250     // %vreg1 = COPY %vreg0:sub1
251     // %vreg2<tied3> = V_MAC_{F16, F32} %vreg3, %vreg4, %vreg1<tied0>
252     //
253     //  into
254     // %vreg2<tied3> = V_MAC_{F16, F32} %vreg3, %vreg4, %vreg0:sub1<tied0>
255     if (UseOp.isTied() && OpToFold.getSubReg() != AMDGPU::NoSubRegister)
256       return;
257   }
258 
259   // Special case for REG_SEQUENCE: We can't fold literals into
260   // REG_SEQUENCE instructions, so we have to fold them into the
261   // uses of REG_SEQUENCE.
262   if (UseMI->isRegSequence()) {
263     unsigned RegSeqDstReg = UseMI->getOperand(0).getReg();
264     unsigned RegSeqDstSubReg = UseMI->getOperand(UseOpIdx + 1).getImm();
265 
266     for (MachineRegisterInfo::use_iterator
267            RSUse = MRI.use_begin(RegSeqDstReg), RSE = MRI.use_end();
268          RSUse != RSE; ++RSUse) {
269 
270       MachineInstr *RSUseMI = RSUse->getParent();
271       if (RSUse->getSubReg() != RegSeqDstSubReg)
272         continue;
273 
274       foldOperand(OpToFold, RSUseMI, RSUse.getOperandNo(), FoldList,
275                   CopiesToReplace, TII, TRI, MRI);
276     }
277 
278     return;
279   }
280 
281 
282   bool FoldingImm = OpToFold.isImm();
283 
284   // In order to fold immediates into copies, we need to change the
285   // copy to a MOV.
286   if (FoldingImm && UseMI->isCopy()) {
287     unsigned DestReg = UseMI->getOperand(0).getReg();
288     const TargetRegisterClass *DestRC
289       = TargetRegisterInfo::isVirtualRegister(DestReg) ?
290       MRI.getRegClass(DestReg) :
291       TRI.getPhysRegClass(DestReg);
292 
293     unsigned MovOp = TII->getMovOpcode(DestRC);
294     if (MovOp == AMDGPU::COPY)
295       return;
296 
297     UseMI->setDesc(TII->get(MovOp));
298     CopiesToReplace.push_back(UseMI);
299   } else {
300     const MCInstrDesc &UseDesc = UseMI->getDesc();
301 
302     // Don't fold into target independent nodes.  Target independent opcodes
303     // don't have defined register classes.
304     if (UseDesc.isVariadic() ||
305         UseDesc.OpInfo[UseOpIdx].RegClass == -1)
306       return;
307   }
308 
309   if (!FoldingImm) {
310     tryAddToFoldList(FoldList, UseMI, UseOpIdx, &OpToFold, TII);
311 
312     // FIXME: We could try to change the instruction from 64-bit to 32-bit
313     // to enable more folding opportunites.  The shrink operands pass
314     // already does this.
315     return;
316   }
317 
318   APInt Imm(64, OpToFold.getImm());
319 
320   const MCInstrDesc &FoldDesc = OpToFold.getParent()->getDesc();
321   const TargetRegisterClass *FoldRC =
322     TRI.getRegClass(FoldDesc.OpInfo[0].RegClass);
323 
324   // Split 64-bit constants into 32-bits for folding.
325   if (UseOp.getSubReg() && AMDGPU::getRegBitWidth(FoldRC->getID()) == 64) {
326     unsigned UseReg = UseOp.getReg();
327     const TargetRegisterClass *UseRC
328       = TargetRegisterInfo::isVirtualRegister(UseReg) ?
329       MRI.getRegClass(UseReg) :
330       TRI.getPhysRegClass(UseReg);
331 
332     if (AMDGPU::getRegBitWidth(UseRC->getID()) != 64)
333       return;
334 
335     if (UseOp.getSubReg() == AMDGPU::sub0) {
336       Imm = Imm.getLoBits(32);
337     } else {
338       assert(UseOp.getSubReg() == AMDGPU::sub1);
339       Imm = Imm.getHiBits(32);
340     }
341   }
342 
343   MachineOperand ImmOp = MachineOperand::CreateImm(Imm.getSExtValue());
344   tryAddToFoldList(FoldList, UseMI, UseOpIdx, &ImmOp, TII);
345 }
346 
347 static bool evalBinaryInstruction(unsigned Opcode, int32_t &Result,
348                                   int32_t LHS, int32_t RHS) {
349   switch (Opcode) {
350   case AMDGPU::V_AND_B32_e64:
351   case AMDGPU::S_AND_B32:
352     Result = LHS & RHS;
353     return true;
354   case AMDGPU::V_OR_B32_e64:
355   case AMDGPU::S_OR_B32:
356     Result = LHS | RHS;
357     return true;
358   case AMDGPU::V_XOR_B32_e64:
359   case AMDGPU::S_XOR_B32:
360     Result = LHS ^ RHS;
361     return true;
362   default:
363     return false;
364   }
365 }
366 
367 static unsigned getMovOpc(bool IsScalar) {
368   return IsScalar ? AMDGPU::S_MOV_B32 : AMDGPU::V_MOV_B32_e32;
369 }
370 
371 /// Remove any leftover implicit operands from mutating the instruction. e.g.
372 /// if we replace an s_and_b32 with a copy, we don't need the implicit scc def
373 /// anymore.
374 static void stripExtraCopyOperands(MachineInstr &MI) {
375   const MCInstrDesc &Desc = MI.getDesc();
376   unsigned NumOps = Desc.getNumOperands() +
377                     Desc.getNumImplicitUses() +
378                     Desc.getNumImplicitDefs();
379 
380   for (unsigned I = MI.getNumOperands() - 1; I >= NumOps; --I)
381     MI.RemoveOperand(I);
382 }
383 
384 static void mutateCopyOp(MachineInstr &MI, const MCInstrDesc &NewDesc) {
385   MI.setDesc(NewDesc);
386   stripExtraCopyOperands(MI);
387 }
388 
389 // Try to simplify operations with a constant that may appear after instruction
390 // selection.
391 static bool tryConstantFoldOp(MachineRegisterInfo &MRI,
392                               const SIInstrInfo *TII,
393                               MachineInstr *MI) {
394   unsigned Opc = MI->getOpcode();
395 
396   if (Opc == AMDGPU::V_NOT_B32_e64 || Opc == AMDGPU::V_NOT_B32_e32 ||
397       Opc == AMDGPU::S_NOT_B32) {
398     MachineOperand &Src0 = MI->getOperand(1);
399     if (Src0.isImm()) {
400       Src0.setImm(~Src0.getImm());
401       mutateCopyOp(*MI, TII->get(getMovOpc(Opc == AMDGPU::S_NOT_B32)));
402       return true;
403     }
404 
405     return false;
406   }
407 
408   if (!MI->isCommutable())
409     return false;
410 
411   int Src0Idx = AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::src0);
412   int Src1Idx = AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::src1);
413 
414   MachineOperand *Src0 = &MI->getOperand(Src0Idx);
415   MachineOperand *Src1 = &MI->getOperand(Src1Idx);
416   if (!Src0->isImm() && !Src1->isImm())
417     return false;
418 
419   // and k0, k1 -> v_mov_b32 (k0 & k1)
420   // or k0, k1 -> v_mov_b32 (k0 | k1)
421   // xor k0, k1 -> v_mov_b32 (k0 ^ k1)
422   if (Src0->isImm() && Src1->isImm()) {
423     int32_t NewImm;
424     if (!evalBinaryInstruction(Opc, NewImm, Src0->getImm(), Src1->getImm()))
425       return false;
426 
427     const SIRegisterInfo &TRI = TII->getRegisterInfo();
428     bool IsSGPR = TRI.isSGPRReg(MRI, MI->getOperand(0).getReg());
429 
430     Src0->setImm(NewImm);
431     MI->RemoveOperand(Src1Idx);
432     mutateCopyOp(*MI, TII->get(getMovOpc(IsSGPR)));
433     return true;
434   }
435 
436   if (Src0->isImm() && !Src1->isImm()) {
437     std::swap(Src0, Src1);
438     std::swap(Src0Idx, Src1Idx);
439   }
440 
441   int32_t Src1Val = static_cast<int32_t>(Src1->getImm());
442   if (Opc == AMDGPU::V_OR_B32_e64 || Opc == AMDGPU::S_OR_B32) {
443     if (Src1Val == 0) {
444       // y = or x, 0 => y = copy x
445       MI->RemoveOperand(Src1Idx);
446       mutateCopyOp(*MI, TII->get(AMDGPU::COPY));
447     } else if (Src1Val == -1) {
448       // y = or x, -1 => y = v_mov_b32 -1
449       MI->RemoveOperand(Src1Idx);
450       mutateCopyOp(*MI, TII->get(getMovOpc(Opc == AMDGPU::S_OR_B32)));
451     } else
452       return false;
453 
454     return true;
455   }
456 
457   if (MI->getOpcode() == AMDGPU::V_AND_B32_e64 ||
458       MI->getOpcode() == AMDGPU::S_AND_B32) {
459     if (Src1Val == 0) {
460       // y = and x, 0 => y = v_mov_b32 0
461       MI->RemoveOperand(Src0Idx);
462       mutateCopyOp(*MI, TII->get(getMovOpc(Opc == AMDGPU::S_AND_B32)));
463     } else if (Src1Val == -1) {
464       // y = and x, -1 => y = copy x
465       MI->RemoveOperand(Src1Idx);
466       mutateCopyOp(*MI, TII->get(AMDGPU::COPY));
467       stripExtraCopyOperands(*MI);
468     } else
469       return false;
470 
471     return true;
472   }
473 
474   if (MI->getOpcode() == AMDGPU::V_XOR_B32_e64 ||
475       MI->getOpcode() == AMDGPU::S_XOR_B32) {
476     if (Src1Val == 0) {
477       // y = xor x, 0 => y = copy x
478       MI->RemoveOperand(Src1Idx);
479       mutateCopyOp(*MI, TII->get(AMDGPU::COPY));
480     }
481   }
482 
483   return false;
484 }
485 
486 bool SIFoldOperands::runOnMachineFunction(MachineFunction &MF) {
487   if (skipFunction(*MF.getFunction()))
488     return false;
489 
490   const SISubtarget &ST = MF.getSubtarget<SISubtarget>();
491 
492   MachineRegisterInfo &MRI = MF.getRegInfo();
493   const SIInstrInfo *TII = ST.getInstrInfo();
494   const SIRegisterInfo &TRI = TII->getRegisterInfo();
495 
496   for (MachineFunction::iterator BI = MF.begin(), BE = MF.end();
497                                                   BI != BE; ++BI) {
498 
499     MachineBasicBlock &MBB = *BI;
500     MachineBasicBlock::iterator I, Next;
501     for (I = MBB.begin(); I != MBB.end(); I = Next) {
502       Next = std::next(I);
503       MachineInstr &MI = *I;
504 
505       if (!isSafeToFold(MI))
506         continue;
507 
508       unsigned OpSize = TII->getOpSize(MI, 1);
509       MachineOperand &OpToFold = MI.getOperand(1);
510       bool FoldingImm = OpToFold.isImm() || OpToFold.isFI();
511 
512       // FIXME: We could also be folding things like FrameIndexes and
513       // TargetIndexes.
514       if (!FoldingImm && !OpToFold.isReg())
515         continue;
516 
517       if (OpToFold.isReg() &&
518           !TargetRegisterInfo::isVirtualRegister(OpToFold.getReg()))
519         continue;
520 
521       // Prevent folding operands backwards in the function. For example,
522       // the COPY opcode must not be replaced by 1 in this example:
523       //
524       //    %vreg3<def> = COPY %VGPR0; VGPR_32:%vreg3
525       //    ...
526       //    %VGPR0<def> = V_MOV_B32_e32 1, %EXEC<imp-use>
527       MachineOperand &Dst = MI.getOperand(0);
528       if (Dst.isReg() &&
529           !TargetRegisterInfo::isVirtualRegister(Dst.getReg()))
530         continue;
531 
532       // We need mutate the operands of new mov instructions to add implicit
533       // uses of EXEC, but adding them invalidates the use_iterator, so defer
534       // this.
535       SmallVector<MachineInstr *, 4> CopiesToReplace;
536 
537       std::vector<FoldCandidate> FoldList;
538       if (FoldingImm) {
539         unsigned NumLiteralUses = 0;
540         MachineOperand *NonInlineUse = nullptr;
541         int NonInlineUseOpNo = -1;
542 
543         // Try to fold any inline immediate uses, and then only fold other
544         // constants if they have one use.
545         //
546         // The legality of the inline immediate must be checked based on the use
547         // operand, not the defining instruction, because 32-bit instructions
548         // with 32-bit inline immediate sources may be used to materialize
549         // constants used in 16-bit operands.
550         //
551         // e.g. it is unsafe to fold:
552         //  s_mov_b32 s0, 1.0    // materializes 0x3f800000
553         //  v_add_f16 v0, v1, s0 // 1.0 f16 inline immediate sees 0x00003c00
554 
555         // Folding immediates with more than one use will increase program size.
556         // FIXME: This will also reduce register usage, which may be better
557         // in some cases. A better heuristic is needed.
558         for (MachineRegisterInfo::use_iterator
559                Use = MRI.use_begin(Dst.getReg()), E = MRI.use_end();
560              Use != E; ++Use) {
561           MachineInstr *UseMI = Use->getParent();
562 
563           if (TII->isInlineConstant(OpToFold, OpSize)) {
564             foldOperand(OpToFold, UseMI, Use.getOperandNo(), FoldList,
565                         CopiesToReplace, TII, TRI, MRI);
566           } else {
567             if (++NumLiteralUses == 1) {
568               NonInlineUse = &*Use;
569               NonInlineUseOpNo = Use.getOperandNo();
570             }
571           }
572         }
573 
574         if (NumLiteralUses == 1) {
575           MachineInstr *UseMI = NonInlineUse->getParent();
576           foldOperand(OpToFold, UseMI, NonInlineUseOpNo, FoldList,
577                       CopiesToReplace, TII, TRI, MRI);
578         }
579       } else {
580         // Folding register.
581         for (MachineRegisterInfo::use_iterator
582                Use = MRI.use_begin(Dst.getReg()), E = MRI.use_end();
583              Use != E; ++Use) {
584           MachineInstr *UseMI = Use->getParent();
585 
586           foldOperand(OpToFold, UseMI, Use.getOperandNo(), FoldList,
587                       CopiesToReplace, TII, TRI, MRI);
588         }
589       }
590 
591       // Make sure we add EXEC uses to any new v_mov instructions created.
592       for (MachineInstr *Copy : CopiesToReplace)
593         Copy->addImplicitDefUseOperands(MF);
594 
595       for (FoldCandidate &Fold : FoldList) {
596         if (updateOperand(Fold, TRI)) {
597           // Clear kill flags.
598           if (Fold.isReg()) {
599             assert(Fold.OpToFold && Fold.OpToFold->isReg());
600             // FIXME: Probably shouldn't bother trying to fold if not an
601             // SGPR. PeepholeOptimizer can eliminate redundant VGPR->VGPR
602             // copies.
603             MRI.clearKillFlags(Fold.OpToFold->getReg());
604           }
605           DEBUG(dbgs() << "Folded source from " << MI << " into OpNo " <<
606                 static_cast<int>(Fold.UseOpNo) << " of " << *Fold.UseMI << '\n');
607 
608           // Folding the immediate may reveal operations that can be constant
609           // folded or replaced with a copy. This can happen for example after
610           // frame indices are lowered to constants or from splitting 64-bit
611           // constants.
612           tryConstantFoldOp(MRI, TII, Fold.UseMI);
613         }
614       }
615     }
616   }
617   return false;
618 }
619