24#define DEBUG_TYPE "gi-combiner"
52 B.buildSExtInReg(Dst, Src, TruncWidth);
140 const GTrunc *Trunc = cast<GTrunc>(&Root);
141 const GExtOp *Ext = cast<GExtOp>(&ExtMI);
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:
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);
236 const GExtOp *Second = cast<GExtOp>(&SecondMI);
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) {
316 {TargetOpcode::G_BUILD_VECTOR, {DstTy, ElemTy}}) ||
318 !isCastFree(Cast->
getOpcode(), ElemTy, InputElemTy))
324 for (
unsigned I = 0;
I < Elements; ++
I) {
330 B.buildBuildVector(Dst, Casts);
339 const GTrunc *Trunc = cast<GTrunc>(&TruncMI);
340 const GBinOp *BinOp = cast<GBinOp>(&BinopMI);
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) {
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.
LLVM_ABI 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).
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.
LLVM_ABI void finishedChangingAllUsesOfReg()
All instructions reported as changing by changingAllUsesOfReg() have finished being changed.
LLVM_ABI void changingAllUsesOfReg(const MachineRegisterInfo &MRI, Register Reg)
All the instructions using the given register are being changed.
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.
const MachineOperand & getOperand(unsigned i) const
MachineOperand class - Representation of each machine instruction operand.
Register getReg() const
getReg - Returns the register number.
LLVM_ABI bool hasOneNonDBGUse(Register RegNo) const
hasOneNonDBGUse - Return true if there is exactly one non-Debug use of the specified register.
LLVM_ABI 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.
LLVM_ABI void replaceRegWith(Register FromReg, Register ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
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.
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.
std::function< void(MachineIRBuilder &)> BuildFnTy
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.