31#define GET_GICOMBINER_DEPS
32#include "AMDGPUGenPreLegalizeGICombiner.inc"
33#undef GET_GICOMBINER_DEPS
35#define DEBUG_TYPE "amdgpu-prelegalizer-combiner"
41#define GET_GICOMBINER_TYPES
42#include "AMDGPUGenPreLegalizeGICombiner.inc"
43#undef GET_GICOMBINER_TYPES
45class AMDGPUPreLegalizerCombinerImpl :
public Combiner {
47 const AMDGPUPreLegalizerCombinerImplRuleConfig &RuleConfig;
52 AMDGPUPreLegalizerCombinerImpl(
55 const AMDGPUPreLegalizerCombinerImplRuleConfig &RuleConfig,
59 static const char *
getName() {
return "AMDGPUPreLegalizerCombinerImpl"; }
64 struct ClampI64ToI16MatchInfo {
72 ClampI64ToI16MatchInfo &MatchInfo)
const;
75 const ClampI64ToI16MatchInfo &MatchInfo)
const;
78#define GET_GICOMBINER_CLASS_MEMBERS
79#define AMDGPUSubtarget GCNSubtarget
80#include "AMDGPUGenPreLegalizeGICombiner.inc"
81#undef GET_GICOMBINER_CLASS_MEMBERS
85#define GET_GICOMBINER_IMPL
86#define AMDGPUSubtarget GCNSubtarget
87#include "AMDGPUGenPreLegalizeGICombiner.inc"
89#undef GET_GICOMBINER_IMPL
91AMDGPUPreLegalizerCombinerImpl::AMDGPUPreLegalizerCombinerImpl(
94 const AMDGPUPreLegalizerCombinerImplRuleConfig &RuleConfig,
96 :
Combiner(MF, CInfo, &VT, CSEInfo), RuleConfig(RuleConfig), STI(STI),
97 Helper(Observer,
B,
true, &VT, MDT, LI, STI),
99#include
"AMDGPUGenPreLegalizeGICombiner.inc"
104bool AMDGPUPreLegalizerCombinerImpl::tryCombineAll(
MachineInstr &
MI)
const {
105 if (tryCombineAllImpl(
MI))
110bool AMDGPUPreLegalizerCombinerImpl::matchClampI64ToI16(
112 ClampI64ToI16MatchInfo &MatchInfo)
const {
113 assert(
MI.getOpcode() == TargetOpcode::G_TRUNC &&
"Invalid instruction!");
116 const LLT SrcType = MRI.
getType(
MI.getOperand(1).getReg());
120 const LLT DstType = MRI.
getType(
MI.getOperand(0).getReg());
128 auto IsApplicableForCombine = [&MatchInfo](
bool OuterIsMin) ->
bool {
129 const int64_t
Lo = OuterIsMin ? MatchInfo.Cmp2 : MatchInfo.Cmp1;
130 const int64_t
Hi = OuterIsMin ? MatchInfo.Cmp1 : MatchInfo.Cmp2;
133 const int64_t Min = std::numeric_limits<int16_t>::min();
134 const int64_t
Max = std::numeric_limits<int16_t>::max();
147 return IsApplicableForCombine(
true);
155 return IsApplicableForCombine(
false);
169void AMDGPUPreLegalizerCombinerImpl::applyClampI64ToI16(
170 MachineInstr &
MI,
const ClampI64ToI16MatchInfo &MatchInfo)
const {
176 auto Unmerge =
B.buildUnmerge(I32, Src);
178 assert(
MI.getOpcode() != AMDGPU::G_AMDGPU_CVT_PK_I16_I32);
182 B.buildInstr(AMDGPU::G_AMDGPU_CVT_PK_I16_I32, {
V2S16},
183 {Unmerge.getReg(0), Unmerge.getReg(1)},
MI.getFlags());
185 auto MinBoundary = std::min(MatchInfo.Cmp1, MatchInfo.Cmp2);
186 auto MaxBoundary = std::max(MatchInfo.Cmp1, MatchInfo.Cmp2);
187 auto MinBoundaryDst =
B.buildConstant(I32, MinBoundary);
188 auto MaxBoundaryDst =
B.buildConstant(I32, MaxBoundary);
192 auto Med3 =
B.buildInstr(
193 AMDGPU::G_AMDGPU_SMED3, {
I32},
194 {MinBoundaryDst.getReg(0),
Bitcast.getReg(0), MaxBoundaryDst.getReg(0)},
197 B.buildTrunc(
MI.getOperand(0).getReg(), Med3);
199 MI.eraseFromParent();
203 function_ref<GISelCSEInfo *()> GetCSEInfo,
204 function_ref<GISelValueTracking *()> GetVT,
205 function_ref<MachineDominatorTree *()> GetMDT,
207 AMDGPUPreLegalizerCombinerImplRuleConfig RuleConfig;
208 if (!RuleConfig.parseCommandLineOption())
215 const GCNSubtarget &STI = MF.
getSubtarget<GCNSubtarget>();
217 CombinerInfo CInfo(
true,
false,
218 nullptr, EnableOpt,
F.hasOptSize(),
F.hasMinSize());
220 CInfo.MaxIterations = 1;
221 CInfo.ObserverLvl = CombinerInfo::ObserverLevel::SinglePass;
224 CInfo.EnableFullDCE =
true;
226 GISelValueTracking *VT = GetVT();
227 GISelCSEInfo *CSEInfo = GetCSEInfo();
228 MachineDominatorTree *MDT = GetMDT();
229 AMDGPUPreLegalizerCombinerImpl Impl(MF, CInfo, *VT, CSEInfo, RuleConfig, STI,
231 return Impl.combineMachineInstrs();
237class AMDGPUPreLegalizerCombinerLegacy :
public MachineFunctionPass {
241 AMDGPUPreLegalizerCombinerLegacy(
bool IsOptLevelNone =
false)
242 : MachineFunctionPass(
ID), IsOptLevelNone(IsOptLevelNone) {}
244 StringRef getPassName()
const override {
245 return "AMDGPUPreLegalizerCombiner";
250 void getAnalysisUsage(AnalysisUsage &AU)
const override;
257void AMDGPUPreLegalizerCombinerLegacy::getAnalysisUsage(
258 AnalysisUsage &AU)
const {
262 AU.
addRequired<GISelValueTrackingAnalysisLegacy>();
264 if (!IsOptLevelNone) {
273bool AMDGPUPreLegalizerCombinerLegacy::runOnMachineFunction(
282 GISelCSEAnalysisWrapper &
Wrapper =
283 getAnalysis<GISelCSEAnalysisWrapperPass>().getCSEWrapper();
284 return &
Wrapper.get(getAnalysis<TargetPassConfig>().getCSEConfig());
287 return &getAnalysis<GISelValueTrackingAnalysisLegacy>().get(MF);
289 [&]() -> MachineDominatorTree * {
290 return IsOptLevelNone ? nullptr
291 : &getAnalysis<MachineDominatorTreeWrapperPass>()
297char AMDGPUPreLegalizerCombinerLegacy::ID = 0;
299 "Combine AMDGPU machine instrs before legalization",
304 "Combine AMDGPU machine instrs before legalization",
false,
309 return new AMDGPUPreLegalizerCombinerLegacy(IsOptLevelNone);
321 return IsOptLevelNone
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define GET_GICOMBINER_CONSTRUCTOR_INITS
amdgpu aa AMDGPU Address space based Alias Analysis Wrapper
This contains common combine transformations that may be used in a combine pass.
This file declares the targeting of the Machinelegalizer class for AMDGPU.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Provides analysis for continuously CSEing during GISel passes.
This contains common combine transformations that may be used in a combine pass,or by the target else...
Option class for Targets to specify which operations are combined how and when.
This contains the base class for all Combiners generated by TableGen.
AMD GCN specific subclass of TargetSubtarget.
Provides analysis for querying information about KnownBits during GISel passes.
Contains matchers for matching SSA Machine Instructions.
Promote Memory to Register
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
static StringRef getName(Value *V)
Target-Independent Code Generator Pass Configuration Options pass.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
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.
const LegalizerInfo * getLegalizerInfo() const override
To use KnownBitsInfo analysis in a pass, KnownBitsInfo &Info = getAnalysis<GISelValueTrackingInfoAnal...
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
static constexpr LLT fixed_vector(unsigned NumElements, unsigned ScalarSizeInBits)
Get a low-level fixed-width vector of some number of elements and element width.
static LLT integer(unsigned SizeInBits)
Analysis pass which computes a MachineDominatorTree.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
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.
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineFunctionProperties & getProperties() const
Get the function properties.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Representation of each machine instruction.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLT getType(Register Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
PreservedAnalyses & preserve()
Mark an analysis as preserved.
Wrapper class representing virtual and physical registers.
CodeGenOptLevel getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
Target-Independent Code Generator Pass Configuration Options.
@ Bitcast
Perform the operation on a different, but equivalently sized type.
operand_type_match m_Reg()
ConstantMatch< APInt > m_ICst(APInt &Cst)
bool mi_match(Reg R, const MachineRegisterInfo &MRI, Pattern &&P)
BinaryOp_match< LHS, RHS, TargetOpcode::G_SMIN, true > m_GSMin(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, TargetOpcode::G_SMAX, true > m_GSMax(const LHS &L, const RHS &R)
This is an optimization pass for GlobalISel generic memory operations.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
LLVM_ABI void getSelectionDAGFallbackAnalysisUsage(AnalysisUsage &AU)
Modify analysis usage so it preserves passes required for the SelectionDAG fallback.
FunctionPass * createAMDGPUPreLegalizeCombinerLegacyPass(bool IsOptLevelNone)
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.