LLVM  15.0.0git
AMDGPURegBankCombiner.cpp
Go to the documentation of this file.
1 //=== lib/CodeGen/GlobalISel/AMDGPURegBankCombiner.cpp ---------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This pass does combining of machine instructions at the generic MI level,
10 // after register banks are known.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "AMDGPU.h"
15 #include "AMDGPULegalizerInfo.h"
16 #include "AMDGPURegisterBankInfo.h"
17 #include "GCNSubtarget.h"
19 #include "SIMachineFunctionInfo.h"
27 #include "llvm/IR/IntrinsicsAMDGPU.h"
29 #define DEBUG_TYPE "amdgpu-regbank-combiner"
30 
31 using namespace llvm;
32 using namespace MIPatternMatch;
33 
35 protected:
42  const SIInstrInfo &TII;
44 
45 public:
47  : B(B), MF(B.getMF()), MRI(*B.getMRI()),
48  Subtarget(MF.getSubtarget<GCNSubtarget>()),
49  RBI(*Subtarget.getRegBankInfo()), TRI(*Subtarget.getRegisterInfo()),
50  TII(*Subtarget.getInstrInfo()), Helper(Helper){};
51 
52  bool isVgprRegBank(Register Reg);
53  Register getAsVgpr(Register Reg);
54 
55  struct MinMaxMedOpc {
56  unsigned Min, Max, Med;
57  };
58 
59  struct Med3MatchInfo {
60  unsigned Opc;
61  Register Val0, Val1, Val2;
62  };
63 
64  MinMaxMedOpc getMinMaxPair(unsigned Opc);
65 
66  template <class m_Cst, typename CstTy>
67  bool matchMed(MachineInstr &MI, MachineRegisterInfo &MRI, MinMaxMedOpc MMMOpc,
68  Register &Val, CstTy &K0, CstTy &K1);
69 
70  bool matchIntMinMaxToMed3(MachineInstr &MI, Med3MatchInfo &MatchInfo);
71  bool matchFPMinMaxToMed3(MachineInstr &MI, Med3MatchInfo &MatchInfo);
72  bool matchFPMinMaxToClamp(MachineInstr &MI, Register &Reg);
73  bool matchFPMed3ToClamp(MachineInstr &MI, Register &Reg);
74  void applyMed3(MachineInstr &MI, Med3MatchInfo &MatchInfo);
75  void applyClamp(MachineInstr &MI, Register &Reg);
76 
77 private:
78  AMDGPU::SIModeRegisterDefaults getMode();
79  bool getIEEE();
80  bool getDX10Clamp();
81  bool isFminnumIeee(const MachineInstr &MI);
82  bool isFCst(MachineInstr *MI);
84 };
85 
87  return RBI.getRegBank(Reg, MRI, TRI)->getID() == AMDGPU::VGPRRegBankID;
88 }
89 
91  if (isVgprRegBank(Reg))
92  return Reg;
93 
94  // Search for existing copy of Reg to vgpr.
96  Register Def = Use.getOperand(0).getReg();
97  if (Use.getOpcode() == AMDGPU::COPY && isVgprRegBank(Def))
98  return Def;
99  }
100 
101  // Copy Reg to vgpr.
102  Register VgprReg = B.buildCopy(MRI.getType(Reg), Reg).getReg(0);
103  MRI.setRegBank(VgprReg, RBI.getRegBank(AMDGPU::VGPRRegBankID));
104  return VgprReg;
105 }
106 
109  switch (Opc) {
110  default:
111  llvm_unreachable("Unsupported opcode");
112  case AMDGPU::G_SMAX:
113  case AMDGPU::G_SMIN:
114  return {AMDGPU::G_SMIN, AMDGPU::G_SMAX, AMDGPU::G_AMDGPU_SMED3};
115  case AMDGPU::G_UMAX:
116  case AMDGPU::G_UMIN:
117  return {AMDGPU::G_UMIN, AMDGPU::G_UMAX, AMDGPU::G_AMDGPU_UMED3};
118  case AMDGPU::G_FMAXNUM:
119  case AMDGPU::G_FMINNUM:
120  return {AMDGPU::G_FMINNUM, AMDGPU::G_FMAXNUM, AMDGPU::G_AMDGPU_FMED3};
121  case AMDGPU::G_FMAXNUM_IEEE:
122  case AMDGPU::G_FMINNUM_IEEE:
123  return {AMDGPU::G_FMINNUM_IEEE, AMDGPU::G_FMAXNUM_IEEE,
124  AMDGPU::G_AMDGPU_FMED3};
125  }
126 }
127 
128 template <class m_Cst, typename CstTy>
131  MinMaxMedOpc MMMOpc, Register &Val,
132  CstTy &K0, CstTy &K1) {
133  // 4 operand commutes of: min(max(Val, K0), K1).
134  // Find K1 from outer instr: min(max(...), K1) or min(K1, max(...)).
135  // Find K0 and Val from inner instr: max(K0, Val) or max(Val, K0).
136  // 4 operand commutes of: max(min(Val, K1), K0).
137  // Find K0 from outer instr: max(min(...), K0) or max(K0, min(...)).
138  // Find K1 and Val from inner instr: min(K1, Val) or min(Val, K1).
139  return mi_match(
140  MI, MRI,
141  m_any_of(
143  MMMOpc.Min, m_CommutativeBinOp(MMMOpc.Max, m_Reg(Val), m_Cst(K0)),
144  m_Cst(K1)),
146  MMMOpc.Max, m_CommutativeBinOp(MMMOpc.Min, m_Reg(Val), m_Cst(K1)),
147  m_Cst(K0))));
148 }
149 
151  MachineInstr &MI, Med3MatchInfo &MatchInfo) {
152  Register Dst = MI.getOperand(0).getReg();
153  if (!isVgprRegBank(Dst))
154  return false;
155 
156  if (MRI.getType(Dst).isVector())
157  return false;
158 
159  MinMaxMedOpc OpcodeTriple = getMinMaxPair(MI.getOpcode());
160  Register Val;
161  Optional<ValueAndVReg> K0, K1;
162  // Match min(max(Val, K0), K1) or max(min(Val, K1), K0). Then see if K0 <= K1.
163  if (!matchMed<GCstAndRegMatch>(MI, MRI, OpcodeTriple, Val, K0, K1))
164  return false;
165 
166  if (OpcodeTriple.Med == AMDGPU::G_AMDGPU_SMED3 && K0->Value.sgt(K1->Value))
167  return false;
168  if (OpcodeTriple.Med == AMDGPU::G_AMDGPU_UMED3 && K0->Value.ugt(K1->Value))
169  return false;
170 
171  MatchInfo = {OpcodeTriple.Med, Val, K0->VReg, K1->VReg};
172  return true;
173 }
174 
175 // fmed3(NaN, K0, K1) = min(min(NaN, K0), K1)
176 // ieee = true : min/max(SNaN, K) = QNaN, min/max(QNaN, K) = K
177 // ieee = false : min/max(NaN, K) = K
178 // clamp(NaN) = dx10_clamp ? 0.0 : NaN
179 // Consider values of min(max(Val, K0), K1) and max(min(Val, K1), K0) as input.
180 // Other operand commutes (see matchMed) give same result since min and max are
181 // commutative.
182 
183 // Try to replace fp min(max(Val, K0), K1) or max(min(Val, K1), K0), KO<=K1
184 // with fmed3(Val, K0, K1) or clamp(Val). Clamp requires K0 = 0.0 and K1 = 1.0.
185 // Val = SNaN only for ieee = true
186 // fmed3(SNaN, K0, K1) = min(min(SNaN, K0), K1) = min(QNaN, K1) = K1
187 // min(max(SNaN, K0), K1) = min(QNaN, K1) = K1
188 // max(min(SNaN, K1), K0) = max(K1, K0) = K1
189 // Val = NaN,ieee = false or Val = QNaN,ieee = true
190 // fmed3(NaN, K0, K1) = min(min(NaN, K0), K1) = min(K0, K1) = K0
191 // min(max(NaN, K0), K1) = min(K0, K1) = K0 (can clamp when dx10_clamp = true)
192 // max(min(NaN, K1), K0) = max(K1, K0) = K1 != K0
194  MachineInstr &MI, Med3MatchInfo &MatchInfo) {
195  Register Dst = MI.getOperand(0).getReg();
196  LLT Ty = MRI.getType(Dst);
197 
198  // med3 for f16 is only available on gfx9+, and not available for v2f16.
199  if ((Ty != LLT::scalar(16) || !Subtarget.hasMed3_16()) &&
200  Ty != LLT::scalar(32))
201  return false;
202 
203  auto OpcodeTriple = getMinMaxPair(MI.getOpcode());
204 
205  Register Val;
207  // Match min(max(Val, K0), K1) or max(min(Val, K1), K0). Then see if K0 <= K1.
208  if (!matchMed<GFCstAndRegMatch>(MI, MRI, OpcodeTriple, Val, K0, K1))
209  return false;
210 
211  if (K0->Value > K1->Value)
212  return false;
213 
214  // For IEEE=false perform combine only when it's safe to assume that there are
215  // no NaN inputs. Most often MI is marked with nnan fast math flag.
216  // For IEEE=true consider NaN inputs. fmed3(NaN, K0, K1) is equivalent to
217  // min(min(NaN, K0), K1). Safe to fold for min(max(Val, K0), K1) since inner
218  // nodes(max/min) have same behavior when one input is NaN and other isn't.
219  // Don't consider max(min(SNaN, K1), K0) since there is no isKnownNeverQNaN,
220  // also post-legalizer inputs to min/max are fcanonicalized (never SNaN).
221  if ((getIEEE() && isFminnumIeee(MI)) || isKnownNeverNaN(Dst, MRI)) {
222  // Don't fold single use constant that can't be inlined.
223  if ((!MRI.hasOneNonDBGUse(K0->VReg) || TII.isInlineConstant(K0->Value)) &&
224  (!MRI.hasOneNonDBGUse(K1->VReg) || TII.isInlineConstant(K1->Value))) {
225  MatchInfo = {OpcodeTriple.Med, Val, K0->VReg, K1->VReg};
226  return true;
227  }
228  }
229 
230  return false;
231 }
232 
234  Register &Reg) {
235  // Clamp is available on all types after regbankselect (f16, f32, f64, v2f16).
236  auto OpcodeTriple = getMinMaxPair(MI.getOpcode());
237  Register Val;
239  // Match min(max(Val, K0), K1) or max(min(Val, K1), K0).
240  if (!matchMed<GFCstOrSplatGFCstMatch>(MI, MRI, OpcodeTriple, Val, K0, K1))
241  return false;
242 
243  if (!K0->Value.isExactlyValue(0.0) || !K1->Value.isExactlyValue(1.0))
244  return false;
245 
246  // For IEEE=false perform combine only when it's safe to assume that there are
247  // no NaN inputs. Most often MI is marked with nnan fast math flag.
248  // For IEEE=true consider NaN inputs. Only min(max(QNaN, 0.0), 1.0) evaluates
249  // to 0.0 requires dx10_clamp = true.
250  if ((getIEEE() && getDX10Clamp() && isFminnumIeee(MI) &&
251  isKnownNeverSNaN(Val, MRI)) ||
252  isKnownNeverNaN(MI.getOperand(0).getReg(), MRI)) {
253  Reg = Val;
254  return true;
255  }
256 
257  return false;
258 }
259 
260 // Replacing fmed3(NaN, 0.0, 1.0) with clamp. Requires dx10_clamp = true.
261 // Val = SNaN only for ieee = true. It is important which operand is NaN.
262 // min(min(SNaN, 0.0), 1.0) = min(QNaN, 1.0) = 1.0
263 // min(min(SNaN, 1.0), 0.0) = min(QNaN, 0.0) = 0.0
264 // min(min(0.0, 1.0), SNaN) = min(0.0, SNaN) = QNaN
265 // Val = NaN,ieee = false or Val = QNaN,ieee = true
266 // min(min(NaN, 0.0), 1.0) = min(0.0, 1.0) = 0.0
267 // min(min(NaN, 1.0), 0.0) = min(1.0, 0.0) = 0.0
268 // min(min(0.0, 1.0), NaN) = min(0.0, NaN) = 0.0
270  Register &Reg) {
271  if (MI.getIntrinsicID() != Intrinsic::amdgcn_fmed3)
272  return false;
273 
274  // In llvm-ir, clamp is often represented as an intrinsic call to
275  // @llvm.amdgcn.fmed3.f32(%Val, 0.0, 1.0). Check for other operand orders.
276  MachineInstr *Src0 = getDefIgnoringCopies(MI.getOperand(2).getReg(), MRI);
277  MachineInstr *Src1 = getDefIgnoringCopies(MI.getOperand(3).getReg(), MRI);
278  MachineInstr *Src2 = getDefIgnoringCopies(MI.getOperand(4).getReg(), MRI);
279 
280  if (isFCst(Src0) && !isFCst(Src1))
281  std::swap(Src0, Src1);
282  if (isFCst(Src1) && !isFCst(Src2))
283  std::swap(Src1, Src2);
284  if (isFCst(Src0) && !isFCst(Src1))
285  std::swap(Src0, Src1);
286  if (!isClampZeroToOne(Src1, Src2))
287  return false;
288 
289  Register Val = Src0->getOperand(0).getReg();
290 
291  auto isOp3Zero = [&]() {
292  MachineInstr *Op3 = getDefIgnoringCopies(MI.getOperand(4).getReg(), MRI);
293  if (Op3->getOpcode() == TargetOpcode::G_FCONSTANT)
294  return Op3->getOperand(1).getFPImm()->isExactlyValue(0.0);
295  return false;
296  };
297  // For IEEE=false perform combine only when it's safe to assume that there are
298  // no NaN inputs. Most often MI is marked with nnan fast math flag.
299  // For IEEE=true consider NaN inputs. Requires dx10_clamp = true. Safe to fold
300  // when Val could be QNaN. If Val can also be SNaN third input should be 0.0.
301  if (isKnownNeverNaN(MI.getOperand(0).getReg(), MRI) ||
302  (getIEEE() && getDX10Clamp() &&
303  (isKnownNeverSNaN(Val, MRI) || isOp3Zero()))) {
304  Reg = Val;
305  return true;
306  }
307 
308  return false;
309 }
310 
312  B.setInstrAndDebugLoc(MI);
313  B.buildInstr(AMDGPU::G_AMDGPU_CLAMP, {MI.getOperand(0)}, {Reg},
314  MI.getFlags());
315  MI.eraseFromParent();
316 }
317 
319  Med3MatchInfo &MatchInfo) {
320  B.setInstrAndDebugLoc(MI);
321  B.buildInstr(MatchInfo.Opc, {MI.getOperand(0)},
322  {getAsVgpr(MatchInfo.Val0), getAsVgpr(MatchInfo.Val1),
323  getAsVgpr(MatchInfo.Val2)},
324  MI.getFlags());
325  MI.eraseFromParent();
326 }
327 
328 AMDGPU::SIModeRegisterDefaults AMDGPURegBankCombinerHelper::getMode() {
329  return MF.getInfo<SIMachineFunctionInfo>()->getMode();
330 }
331 
332 bool AMDGPURegBankCombinerHelper::getIEEE() { return getMode().IEEE; }
333 
334 bool AMDGPURegBankCombinerHelper::getDX10Clamp() { return getMode().DX10Clamp; }
335 
336 bool AMDGPURegBankCombinerHelper::isFminnumIeee(const MachineInstr &MI) {
337  return MI.getOpcode() == AMDGPU::G_FMINNUM_IEEE;
338 }
339 
340 bool AMDGPURegBankCombinerHelper::isFCst(MachineInstr *MI) {
341  return MI->getOpcode() == AMDGPU::G_FCONSTANT;
342 }
343 
344 bool AMDGPURegBankCombinerHelper::isClampZeroToOne(MachineInstr *K0,
345  MachineInstr *K1) {
346  if (isFCst(K0) && isFCst(K1)) {
347  const ConstantFP *KO_FPImm = K0->getOperand(1).getFPImm();
348  const ConstantFP *K1_FPImm = K1->getOperand(1).getFPImm();
349  return (KO_FPImm->isExactlyValue(0.0) && K1_FPImm->isExactlyValue(1.0)) ||
350  (KO_FPImm->isExactlyValue(1.0) && K1_FPImm->isExactlyValue(0.0));
351  }
352  return false;
353 }
354 
356 protected:
359 
360 public:
362  AMDGPURegBankCombinerHelper &RegBankHelper)
363  : Helper(Helper), RegBankHelper(RegBankHelper) {}
364 };
365 
366 #define AMDGPUREGBANKCOMBINERHELPER_GENCOMBINERHELPER_DEPS
367 #include "AMDGPUGenRegBankGICombiner.inc"
368 #undef AMDGPUREGBANKCOMBINERHELPER_GENCOMBINERHELPER_DEPS
369 
370 namespace {
371 #define AMDGPUREGBANKCOMBINERHELPER_GENCOMBINERHELPER_H
372 #include "AMDGPUGenRegBankGICombiner.inc"
373 #undef AMDGPUREGBANKCOMBINERHELPER_GENCOMBINERHELPER_H
374 
375 class AMDGPURegBankCombinerInfo final : public CombinerInfo {
376  GISelKnownBits *KB;
378 
379 public:
380  AMDGPUGenRegBankCombinerHelperRuleConfig GeneratedRuleCfg;
381 
382  AMDGPURegBankCombinerInfo(bool EnableOpt, bool OptSize, bool MinSize,
383  const AMDGPULegalizerInfo *LI,
385  : CombinerInfo(/*AllowIllegalOps*/ false, /*ShouldLegalizeIllegal*/ true,
386  /*LegalizerInfo*/ LI, EnableOpt, OptSize, MinSize),
387  KB(KB), MDT(MDT) {
388  if (!GeneratedRuleCfg.parseCommandLineOption())
389  report_fatal_error("Invalid rule identifier");
390  }
391 
392  bool combine(GISelChangeObserver &Observer, MachineInstr &MI,
393  MachineIRBuilder &B) const override;
394 };
395 
397  MachineInstr &MI,
398  MachineIRBuilder &B) const {
399  CombinerHelper Helper(Observer, B, KB, MDT);
400  AMDGPURegBankCombinerHelper RegBankHelper(B, Helper);
401  AMDGPUGenRegBankCombinerHelper Generated(GeneratedRuleCfg, Helper,
402  RegBankHelper);
403 
404  if (Generated.tryCombineAll(Observer, MI, B))
405  return true;
406 
407  return false;
408 }
409 
410 #define AMDGPUREGBANKCOMBINERHELPER_GENCOMBINERHELPER_CPP
411 #include "AMDGPUGenRegBankGICombiner.inc"
412 #undef AMDGPUREGBANKCOMBINERHELPER_GENCOMBINERHELPER_CPP
413 
414 // Pass boilerplate
415 // ================
416 
417 class AMDGPURegBankCombiner : public MachineFunctionPass {
418 public:
419  static char ID;
420 
421  AMDGPURegBankCombiner(bool IsOptNone = false);
422 
423  StringRef getPassName() const override {
424  return "AMDGPURegBankCombiner";
425  }
426 
427  bool runOnMachineFunction(MachineFunction &MF) override;
428 
429  void getAnalysisUsage(AnalysisUsage &AU) const override;
430 private:
431  bool IsOptNone;
432 };
433 } // end anonymous namespace
434 
435 void AMDGPURegBankCombiner::getAnalysisUsage(AnalysisUsage &AU) const {
437  AU.setPreservesCFG();
441  if (!IsOptNone) {
444  }
446 }
447 
448 AMDGPURegBankCombiner::AMDGPURegBankCombiner(bool IsOptNone)
449  : MachineFunctionPass(ID), IsOptNone(IsOptNone) {
450  initializeAMDGPURegBankCombinerPass(*PassRegistry::getPassRegistry());
451 }
452 
453 bool AMDGPURegBankCombiner::runOnMachineFunction(MachineFunction &MF) {
454  if (MF.getProperties().hasProperty(
455  MachineFunctionProperties::Property::FailedISel))
456  return false;
457  auto *TPC = &getAnalysis<TargetPassConfig>();
458  const Function &F = MF.getFunction();
459  bool EnableOpt =
460  MF.getTarget().getOptLevel() != CodeGenOpt::None && !skipFunction(F);
461 
462  const GCNSubtarget &ST = MF.getSubtarget<GCNSubtarget>();
463  const AMDGPULegalizerInfo *LI
464  = static_cast<const AMDGPULegalizerInfo *>(ST.getLegalizerInfo());
465 
466  GISelKnownBits *KB = &getAnalysis<GISelKnownBitsAnalysis>().get(MF);
467  MachineDominatorTree *MDT =
468  IsOptNone ? nullptr : &getAnalysis<MachineDominatorTree>();
469  AMDGPURegBankCombinerInfo PCInfo(EnableOpt, F.hasOptSize(),
470  F.hasMinSize(), LI, KB, MDT);
471  Combiner C(PCInfo, TPC);
472  return C.combineMachineInstrs(MF, /*CSEInfo*/ nullptr);
473 }
474 
476 INITIALIZE_PASS_BEGIN(AMDGPURegBankCombiner, DEBUG_TYPE,
477  "Combine AMDGPU machine instrs after regbankselect",
478  false, false)
481 INITIALIZE_PASS_END(AMDGPURegBankCombiner, DEBUG_TYPE,
482  "Combine AMDGPU machine instrs after regbankselect", false,
483  false)
484 
485 namespace llvm {
487  return new AMDGPURegBankCombiner(IsOptNone);
488 }
489 } // end namespace llvm
MIPatternMatch.h
llvm::TargetMachine::getOptLevel
CodeGenOpt::Level getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
Definition: TargetMachine.cpp:186
CombinerInfo.h
AMDGPURegBankCombinerHelper::applyClamp
void applyClamp(MachineInstr &MI, Register &Reg)
Definition: AMDGPURegBankCombiner.cpp:311
AMDGPURegBankCombinerHelper::MRI
MachineRegisterInfo & MRI
Definition: AMDGPURegBankCombiner.cpp:38
llvm::MachineFunctionProperties::hasProperty
bool hasProperty(Property P) const
Definition: MachineFunction.h:176
llvm::getDefIgnoringCopies
MachineInstr * getDefIgnoringCopies(Register Reg, const MachineRegisterInfo &MRI)
Find the def instruction for Reg, folding away any trivial copies.
Definition: Utils.cpp:460
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:104
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::tgtok::Def
@ Def
Definition: TGLexer.h:50
AMDGPURegBankCombinerHelper::Helper
CombinerHelper & Helper
Definition: AMDGPURegBankCombiner.cpp:43
llvm::FPValueAndVReg::Value
APFloat Value
Definition: Utils.h:198
llvm::MIPatternMatch::m_Reg
operand_type_match m_Reg()
Definition: MIPatternMatch.h:252
SIMachineFunctionInfo.h
llvm::GISelKnownBits
Definition: GISelKnownBits.h:29
AMDGPURegBankCombinerHelper::getMinMaxPair
MinMaxMedOpc getMinMaxPair(unsigned Opc)
Definition: AMDGPURegBankCombiner.cpp:108
llvm::MachineRegisterInfo
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Definition: MachineRegisterInfo.h:50
llvm::Function
Definition: Function.h:60
AMDGPURegBankCombinerHelper::MF
MachineFunction & MF
Definition: AMDGPURegBankCombiner.cpp:37
AMDGPURegBankCombinerHelper::isVgprRegBank
bool isVgprRegBank(Register Reg)
Definition: AMDGPURegBankCombiner.cpp:86
GISelKnownBits.h
regbankselect
Combine AMDGPU machine instrs after regbankselect
Definition: AMDGPURegBankCombiner.cpp:482
AMDGPURegBankCombinerHelper::MinMaxMedOpc::Max
unsigned Max
Definition: AMDGPURegBankCombiner.cpp:56
llvm::X86Disassembler::Reg
Reg
All possible values of the reg field in the ModR/M byte.
Definition: X86DisassemblerDecoder.h:462
llvm::MachineFunctionPass
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Definition: MachineFunctionPass.h:30
AMDGPURegBankCombinerHelper::matchFPMed3ToClamp
bool matchFPMed3ToClamp(MachineInstr &MI, Register &Reg)
Definition: AMDGPURegBankCombiner.cpp:269
AMDGPURegBankCombinerHelper::AMDGPURegBankCombinerHelper
AMDGPURegBankCombinerHelper(MachineIRBuilder &B, CombinerHelper &Helper)
Definition: AMDGPURegBankCombiner.cpp:46
llvm::TargetRegisterInfo
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Definition: TargetRegisterInfo.h:234
AMDGPURegBankCombinerHelper::matchMed
bool matchMed(MachineInstr &MI, MachineRegisterInfo &MRI, MinMaxMedOpc MMMOpc, Register &Val, CstTy &K0, CstTy &K1)
Definition: AMDGPURegBankCombiner.cpp:129
llvm::MachineRegisterInfo::use_instructions
iterator_range< use_instr_iterator > use_instructions(Register Reg) const
Definition: MachineRegisterInfo.h:493
llvm::APInt::ugt
bool ugt(const APInt &RHS) const
Unsigned greater than comparison.
Definition: APInt.h:1132
llvm::Optional
Definition: APInt.h:33
llvm::getSelectionDAGFallbackAnalysisUsage
void getSelectionDAGFallbackAnalysisUsage(AnalysisUsage &AU)
Modify analysis usage so it preserves passes required for the SelectionDAG fallback.
Definition: Utils.cpp:879
llvm::GCNSubtarget
Definition: GCNSubtarget.h:31
llvm::CombinerInfo
Definition: CombinerInfo.h:26
TRI
unsigned const TargetRegisterInfo * TRI
Definition: MachineSink.cpp:1620
llvm::ValueAndVReg::Value
APInt Value
Definition: Utils.h:180
llvm::MachineFunctionPass::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Definition: MachineFunctionPass.cpp:103
llvm::AMDGPULegalizerInfo
This class provides the information for the target register banks.
Definition: AMDGPULegalizerInfo.h:31
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::ValueAndVReg::VReg
Register VReg
Definition: Utils.h:181
AMDGPURegBankCombinerHelperState::RegBankHelper
AMDGPURegBankCombinerHelper & RegBankHelper
Definition: AMDGPURegBankCombiner.cpp:358
llvm::GISelKnownBitsAnalysis
To use KnownBitsInfo analysis in a pass, KnownBitsInfo &Info = getAnalysis<GISelKnownBitsInfoAnalysis...
Definition: GISelKnownBits.h:113
TargetMachine.h
GCNSubtarget.h
AMDGPURegBankCombinerHelper::Med3MatchInfo
Definition: AMDGPURegBankCombiner.cpp:59
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::MachineInstr::getOperand
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:501
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
llvm::MachineFunction::getProperties
const MachineFunctionProperties & getProperties() const
Get the function properties.
Definition: MachineFunction.h:731
false
Definition: StackSlotColoring.cpp:141
isClampZeroToOne
static bool isClampZeroToOne(SDValue A, SDValue B)
Definition: SIISelLowering.cpp:10357
TII
const HexagonInstrInfo * TII
Definition: HexagonCopyToCombine.cpp:127
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
AMDGPU
Definition: AMDGPUReplaceLDSUseWithPointer.cpp:114
AMDGPURegBankCombinerHelper::MinMaxMedOpc::Min
unsigned Min
Definition: AMDGPURegBankCombiner.cpp:56
AMDGPURegBankCombinerHelperState::AMDGPURegBankCombinerHelperState
AMDGPURegBankCombinerHelperState(CombinerHelper &Helper, AMDGPURegBankCombinerHelper &RegBankHelper)
Definition: AMDGPURegBankCombiner.cpp:361
AMDGPURegBankCombinerHelper::TII
const SIInstrInfo & TII
Definition: AMDGPURegBankCombiner.cpp:42
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:143
llvm::ConstantFP
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:257
llvm::ConstantFP::isExactlyValue
bool isExactlyValue(const APFloat &V) const
We don't rely on operator== working on double values, as it returns true for things that are clearly ...
Definition: Constants.cpp:1090
llvm::CombinerHelper
Definition: CombinerHelper.h:108
llvm::FPValueAndVReg::VReg
Register VReg
Definition: Utils.h:199
llvm::None
const NoneType None
Definition: None.h:24
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
INITIALIZE_PASS_END
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:58
llvm::TargetPassConfig
Target-Independent Code Generator Pass Configuration Options.
Definition: TargetPassConfig.h:84
AMDGPURegBankCombinerHelper
Definition: AMDGPURegBankCombiner.cpp:34
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition: MachineFunction.h:640
Combine
Hexagon Vector Combine
Definition: HexagonVectorCombine.cpp:1527
AMDGPURegBankCombinerHelper::Med3MatchInfo::Opc
unsigned Opc
Definition: AMDGPURegBankCombiner.cpp:60
llvm::RegisterBankInfo
Holds all the information related to register banks.
Definition: RegisterBankInfo.h:39
AMDGPURegisterBankInfo.h
AMDGPUMCTargetDesc.h
llvm::MachineIRBuilder
Helper class to build MachineInstr.
Definition: MachineIRBuilder.h:219
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:66
llvm::Combiner
Definition: Combiner.h:26
llvm::MachineRegisterInfo::setRegBank
void setRegBank(Register Reg, const RegisterBank &RegBank)
Set the register bank to RegBank for Reg.
Definition: MachineRegisterInfo.cpp:61
DEBUG_TYPE
#define DEBUG_TYPE
Definition: AMDGPURegBankCombiner.cpp:29
llvm::ARM_MB::ST
@ ST
Definition: ARMBaseInfo.h:73
INITIALIZE_PASS_DEPENDENCY
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
AMDGPURegBankCombinerHelper::getAsVgpr
Register getAsVgpr(Register Reg)
Definition: AMDGPURegBankCombiner.cpp:90
AMDGPURegBankCombinerHelper::RBI
const RegisterBankInfo & RBI
Definition: AMDGPURegBankCombiner.cpp:40
llvm::MIPatternMatch::m_CommutativeBinOp
BinaryOpc_match< LHS, RHS, true > m_CommutativeBinOp(unsigned Opcode, const LHS &L, const RHS &R)
Definition: MIPatternMatch.h:416
AMDGPURegBankCombinerHelper::Subtarget
const GCNSubtarget & Subtarget
Definition: AMDGPURegBankCombiner.cpp:39
llvm::LLT::isVector
bool isVector() const
Definition: LowLevelTypeImpl.h:122
TargetPassConfig.h
llvm::MachineOperand::getFPImm
const ConstantFP * getFPImm() const
Definition: MachineOperand.h:556
std::swap
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:853
llvm::MachineOperand::getReg
Register getReg() const
getReg - Returns the register number.
Definition: MachineOperand.h:359
llvm::MachineFunction
Definition: MachineFunction.h:241
AMDGPURegBankCombinerHelper::applyMed3
void applyMed3(MachineInstr &MI, Med3MatchInfo &MatchInfo)
Definition: AMDGPURegBankCombiner.cpp:318
CombinerHelper.h
AMDGPURegBankCombinerHelper::Med3MatchInfo::Val2
Register Val2
Definition: AMDGPURegBankCombiner.cpp:61
llvm::AnalysisUsage::setPreservesCFG
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition: Pass.cpp:263
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
AMDGPU.h
llvm::MachineInstr::getOpcode
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:491
llvm::MachineRegisterInfo::hasOneNonDBGUse
bool hasOneNonDBGUse(Register RegNo) const
hasOneNonDBGUse - Return true if there is exactly one non-Debug use of the specified register.
Definition: MachineRegisterInfo.cpp:415
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::AnalysisUsage::addPreserved
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
Definition: PassAnalysisSupport.h:98
llvm::createAMDGPURegBankCombiner
FunctionPass * createAMDGPURegBankCombiner(bool IsOptNone)
Definition: AMDGPURegBankCombiner.cpp:486
Combiner.h
AMDGPURegBankCombinerHelper::matchFPMinMaxToMed3
bool matchFPMinMaxToMed3(MachineInstr &MI, Med3MatchInfo &MatchInfo)
Definition: AMDGPURegBankCombiner.cpp:193
llvm::MIPatternMatch::m_any_of
Or< Preds... > m_any_of(Preds &&... preds)
Definition: MIPatternMatch.h:296
AMDGPURegBankCombinerHelper::MinMaxMedOpc
Definition: AMDGPURegBankCombiner.cpp:55
AMDGPURegBankCombinerHelper::matchFPMinMaxToClamp
bool matchFPMinMaxToClamp(MachineInstr &MI, Register &Reg)
Definition: AMDGPURegBankCombiner.cpp:233
llvm::GISelChangeObserver
Abstract class that contains various methods for clients to notify about changes.
Definition: GISelChangeObserver.h:29
llvm::isKnownNeverNaN
bool isKnownNeverNaN(const Value *V, const TargetLibraryInfo *TLI, unsigned Depth=0)
Return true if the floating-point scalar value is not a NaN or if the floating-point vector value has...
Definition: ValueTracking.cpp:3704
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
AMDGPURegBankCombinerHelper::MinMaxMedOpc::Med
unsigned Med
Definition: AMDGPURegBankCombiner.cpp:56
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition: MachineFunction.h:606
llvm::MachineFunction::getTarget
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Definition: MachineFunction.h:636
llvm::isKnownNeverSNaN
bool isKnownNeverSNaN(Register Val, const MachineRegisterInfo &MRI)
Returns true if Val can be assumed to never be a signaling NaN.
Definition: Utils.h:301
AMDGPURegBankCombinerHelper::B
MachineIRBuilder & B
Definition: AMDGPURegBankCombiner.cpp:36
llvm::APFloat::isExactlyValue
bool isExactlyValue(double V) const
We don't rely on operator== working on double values, as it returns true for things that are clearly ...
Definition: APFloat.h:1197
llvm::SIInstrInfo
Definition: SIInstrInfo.h:43
AMDGPULegalizerInfo.h
llvm::MachineRegisterInfo::getType
LLT getType(Register Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register.
Definition: MachineRegisterInfo.h:740
AMDGPURegBankCombinerHelperState
Definition: AMDGPURegBankCombiner.cpp:355
llvm::SIMachineFunctionInfo
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
Definition: SIMachineFunctionInfo.h:348
llvm::initializeAMDGPURegBankCombinerPass
void initializeAMDGPURegBankCombinerPass(PassRegistry &)
llvm::APInt::sgt
bool sgt(const APInt &RHS) const
Signed greater than comparison.
Definition: APInt.h:1151
llvm::FunctionPass
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:308
llvm::MIPatternMatch::mi_match
bool mi_match(Reg R, const MachineRegisterInfo &MRI, Pattern &&P)
Definition: MIPatternMatch.h:25
llvm::AnalysisUsage::addRequired
AnalysisUsage & addRequired()
Definition: PassAnalysisSupport.h:75
AMDGPURegBankCombinerHelper::matchIntMinMaxToMed3
bool matchIntMinMaxToMed3(MachineInstr &MI, Med3MatchInfo &MatchInfo)
Definition: AMDGPURegBankCombiner.cpp:150
llvm::MachineDominatorTree
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
Definition: MachineDominators.h:51
combine
vector combine
Definition: VectorCombine.cpp:1548
llvm::LLT::scalar
static LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
Definition: LowLevelTypeImpl.h:42
INITIALIZE_PASS_BEGIN
INITIALIZE_PASS_BEGIN(AMDGPURegBankCombiner, DEBUG_TYPE, "Combine AMDGPU machine instrs after regbankselect", false, false) INITIALIZE_PASS_END(AMDGPURegBankCombiner
AMDGPURegBankCombinerHelper::TRI
const TargetRegisterInfo & TRI
Definition: AMDGPURegBankCombiner.cpp:41
AMDGPURegBankCombinerHelperState::Helper
CombinerHelper & Helper
Definition: AMDGPURegBankCombiner.cpp:357
llvm::Use
A Use represents the edge between a Value definition and its users.
Definition: Use.h:43
MachineDominators.h
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37
llvm::LLT
Definition: LowLevelTypeImpl.h:39