24#define DEBUG_TYPE "gi-combiner"
120 const GTrunc *Trunc = cast<GTrunc>(&Root);
121 const GExtOp *Ext = cast<GExtOp>(&ExtMI);
131 if (SrcTy == DstTy) {
145 B.buildInstr(Ext->getOpcode(), {Dst}, {Src});
165bool CombinerHelper::isCastFree(
unsigned Opcode,
LLT ToTy,
LLT FromTy)
const {
170 case TargetOpcode::G_ANYEXT:
171 case TargetOpcode::G_ZEXT:
173 case TargetOpcode::G_TRUNC:
200 if (!isCastFree(Cast->
getOpcode(), DstTy, SrcTy))
204 auto True =
B.buildInstr(Cast->
getOpcode(), {DstTy}, {TrueReg});
205 auto False =
B.buildInstr(Cast->
getOpcode(), {DstTy}, {FalseReg});
206 B.buildSelect(Dst,
Cond, True, False);
216 const GExtOp *Second = cast<GExtOp>(&SecondMI);
229 if (Second->
getOpcode() == TargetOpcode::G_ZEXT) {
238 B.buildInstr(Second->
getOpcode(), {Dst}, {Src});
245 if (
First->getOpcode() == TargetOpcode::G_ANYEXT &&
247 if (Second->
getOpcode() == TargetOpcode::G_ZEXT) {
260 if (Second->
getOpcode() == TargetOpcode::G_ANYEXT &&
262 if (
First->getOpcode() == TargetOpcode::G_ZEXT) {
296 {TargetOpcode::G_BUILD_VECTOR, {DstTy, ElemTy}}) ||
298 !isCastFree(Cast->
getOpcode(), ElemTy, InputElemTy))
304 for (
unsigned I = 0;
I < Elements; ++
I) {
310 B.buildBuildVector(Dst, Casts);
319 const GTrunc *Trunc = cast<GTrunc>(&TruncMI);
320 const GBinOp *BinOp = cast<GBinOp>(&BinopMI);
342 APInt &MatchInfo)
const {
353 case TargetOpcode::G_TRUNC: {
AMDGPU Register Bank Select
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This contains common combine transformations that may be used in a combine pass,or by the target else...
Interface for Targets to specify which operations they can successfully select and how the others sho...
Implement a low-level type suitable for MachineInstr level instruction selection.
This file declares the MachineIRBuilder class.
const SmallVectorImpl< MachineOperand > & Cond
Class for arbitrary precision integers.
APInt trunc(unsigned width) const
Truncate to new width.
bool matchZextOfTrunc(const MachineOperand &MO, BuildFnTy &MatchInfo) const
Combine zext of trunc.
bool matchNonNegZext(const MachineOperand &MO, BuildFnTy &MatchInfo) const
Combine zext nneg to sext.
const TargetLowering & getTargetLowering() const
bool matchSextOfTrunc(const MachineOperand &MO, BuildFnTy &MatchInfo) const
Combine sext of trunc.
bool matchTruncateOfExt(const MachineInstr &Root, const MachineInstr &ExtMI, BuildFnTy &MatchInfo) const
Transform trunc ([asz]ext x) to x or ([asz]ext x) or (trunc x).
bool matchExtOfExt(const MachineInstr &FirstMI, const MachineInstr &SecondMI, BuildFnTy &MatchInfo) const
LLVMContext & getContext() const
bool isConstantLegalOrBeforeLegalizer(const LLT Ty) const
MachineRegisterInfo & MRI
bool isLegalOrBeforeLegalizer(const LegalityQuery &Query) const
bool matchNarrowBinop(const MachineInstr &TruncMI, const MachineInstr &BinopMI, BuildFnTy &MatchInfo) const
trunc (binop X, C) --> binop (trunc X, trunc C).
bool matchCastOfBuildVector(const MachineInstr &CastMI, const MachineInstr &BVMI, BuildFnTy &MatchInfo) const
bool matchCastOfInteger(const MachineInstr &CastMI, APInt &MatchInfo) const
bool matchCastOfSelect(const MachineInstr &Cast, const MachineInstr &SelectMI, BuildFnTy &MatchInfo) const
Represents a binary operation, i.e, x = y op z.
Register getLHSReg() const
Register getRHSReg() const
Represents a G_BUILD_VECTOR.
Register getSrcReg() const
Represents an integer-like extending operation.
Represents an integer-like extending or truncating operation.
Register getSourceReg(unsigned I) const
Returns the I'th source register.
unsigned getNumSources() const
Returns the number of source registers.
Register getReg(unsigned Idx) const
Access the Idx'th operand as a register and return it.
constexpr unsigned getScalarSizeInBits() const
constexpr LLT getElementType() const
Returns the vector's element type. Only valid for vector types.
constexpr LLT getScalarType() const
This is an important class for using LLVM in a threaded context.
Helper class to build MachineInstr.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
bool getFlag(MIFlag Flag) const
Return whether an MI flag is set.
MachineOperand class - Representation of each machine instruction operand.
Register getReg() const
getReg - Returns the register number.
bool hasOneNonDBGUse(Register RegNo) const
hasOneNonDBGUse - Return true if there is exactly one non-Debug use of the specified register.
MachineInstr * getVRegDef(Register Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
LLT getType(Register Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register.
Wrapper class representing virtual and physical registers.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
virtual bool isZExtFree(Type *FromTy, Type *ToTy) const
Return true if any actual instruction that defines a value of type FromTy implicitly zero-extends the...
virtual bool isTruncateFree(Type *FromTy, Type *ToTy) const
Return true if it's free to truncate a value of type FromTy to type ToTy.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
This is an optimization pass for GlobalISel generic memory operations.
MVT getMVTForLLT(LLT Ty)
Get a rough equivalent of an MVT for a given LLT.
MachineInstr * getDefIgnoringCopies(Register Reg, const MachineRegisterInfo &MRI)
Find the def instruction for Reg, folding away any trivial copies.
std::function< void(MachineIRBuilder &)> BuildFnTy
const APInt & getIConstantFromReg(Register VReg, const MachineRegisterInfo &MRI)
VReg is defined by a G_CONSTANT, return the corresponding value.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.