24#define DEBUG_TYPE "gi-combiner"
36 LLT DstTy =
MRI.getType(Dst);
37 LLT SrcTy =
MRI.getType(Src);
47 unsigned TruncWidth =
MRI.getType(Trunc->
getReg(0)).getScalarSizeInBits();
52 B.buildSExtInReg(Dst, Src, TruncWidth);
89 LLT DstTy =
MRI.getType(Dst);
90 LLT SrcTy =
MRI.getType(Src);
123 LLT DstTy =
MRI.getType(Dst);
124 LLT SrcTy =
MRI.getType(Src);
143 if (!
MRI.hasOneNonDBGUse(Ext->getReg(0)))
148 LLT DstTy =
MRI.getType(Dst);
149 LLT SrcTy =
MRI.getType(Src);
151 if (SrcTy == DstTy) {
165 B.buildInstr(Ext->getOpcode(), {Dst}, {Src});
185bool CombinerHelper::isCastFree(
unsigned Opcode,
LLT ToTy,
LLT FromTy)
const {
190 case TargetOpcode::G_ANYEXT:
191 case TargetOpcode::G_ZEXT:
193 case TargetOpcode::G_TRUNC:
206 if (!
MRI.hasOneNonDBGUse(
Select->getReg(0)))
210 LLT DstTy =
MRI.getType(Dst);
214 LLT SrcTy =
MRI.getType(TrueReg);
220 if (!isCastFree(Cast->
getOpcode(), DstTy, SrcTy))
224 auto True =
B.buildInstr(Cast->
getOpcode(), {DstTy}, {TrueReg});
225 auto False =
B.buildInstr(Cast->
getOpcode(), {DstTy}, {FalseReg});
226 B.buildSelect(Dst,
Cond, True, False);
240 LLT DstTy =
MRI.getType(Dst);
241 LLT SrcTy =
MRI.getType(Src);
243 if (!
MRI.hasOneNonDBGUse(Second->
getReg(0)))
249 if (Second->
getOpcode() == TargetOpcode::G_ZEXT) {
258 B.buildInstr(Second->
getOpcode(), {Dst}, {Src});
265 if (
First->getOpcode() == TargetOpcode::G_ANYEXT &&
267 if (Second->
getOpcode() == TargetOpcode::G_ZEXT) {
280 if (Second->
getOpcode() == TargetOpcode::G_ANYEXT &&
282 if (
First->getOpcode() == TargetOpcode::G_ZEXT) {
307 LLT DstTy =
MRI.getType(Dst);
311 LLT InputElemTy =
MRI.getType(BV->
getReg(0)).getElementType();
316 {TargetOpcode::G_BUILD_VECTOR, {DstTy, ElemTy}}) ||
318 !isCastFree(Cast->
getOpcode(), ElemTy, InputElemTy))
324 for (
unsigned I = 0;
I < Elements; ++
I) {
326 B.buildInstr(Cast->
getOpcode(), {ElemTy}, {BV->getSourceReg(I)});
330 B.buildBuildVector(Dst, Casts);
342 if (!
MRI.hasOneNonDBGUse(BinOp->
getReg(0)))
346 LLT DstTy =
MRI.getType(Dst);
353 auto LHS =
B.buildTrunc(DstTy, BinOp->
getLHSReg());
354 auto RHS =
B.buildTrunc(DstTy, BinOp->
getRHSReg());
355 B.buildInstr(BinOp->
getOpcode(), {Dst}, {LHS, RHS});
362 APInt &MatchInfo)
const {
373 case TargetOpcode::G_TRUNC: {
386 Other.getOpcode() == TargetOpcode::G_SEXT_INREG);
389 unsigned OtherWidth =
Other.getOperand(2).getImm();
395 if (RootWidth >= OtherWidth) {
403 MRI.replaceRegWith(Dst, OtherDst);
404 Observer.finishedChangingAllUsesOfReg();
410 B.buildSExtInReg(Dst, Src, RootWidth);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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.
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).
GISelChangeObserver & Observer
bool matchRedundantSextInReg(MachineInstr &Root, MachineInstr &Other, BuildFnTy &MatchInfo) const
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.
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 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.
const MachineOperand & getOperand(unsigned i) const
MachineOperand class - Representation of each machine instruction operand.
Register getReg() const
getReg - Returns the register number.
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.
std::function< void(MachineIRBuilder &)> BuildFnTy
LLVM_ABI MVT getMVTForLLT(LLT Ty)
Get a rough equivalent of an MVT for a given LLT.
LLVM_ABI MachineInstr * getDefIgnoringCopies(Register Reg, const MachineRegisterInfo &MRI)
Find the def instruction for Reg, folding away any trivial copies.
LLVM_ABI const APInt & getIConstantFromReg(Register VReg, const MachineRegisterInfo &MRI)
VReg is defined by a G_CONSTANT, return the corresponding value.
LLVM_ABI bool canReplaceReg(Register DstReg, Register SrcReg, MachineRegisterInfo &MRI)
Check if DstReg can be replaced with SrcReg depending on the register constraints.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.