27 #define DEBUG_TYPE "si-shrink-instructions"
30 "Number of 64-bit instruction reduced to 32-bit.");
32 "Number of literal constants folded into 32-bit instructions.");
48 StringRef getPassName()
const override {
return "SI Shrink Instructions"; }
59 "SI Shrink Instructions",
false,
false)
61 char SIShrinkInstructions::
ID = 0;
64 return new SIShrinkInstructions();
91 default:
return false;
93 case AMDGPU::V_ADDC_U32_e64:
94 case AMDGPU::V_SUBB_U32_e64:
100 case AMDGPU::V_MAC_F32_e64:
101 case AMDGPU::V_MAC_F16_e64:
102 if (!
isVGPR(Src2, TRI, MRI) ||
107 case AMDGPU::V_CNDMASK_B32_e64:
113 if (Src1 && (!
isVGPR(Src1, TRI, MRI) ||
139 unsigned Reg = Src0.getReg();
144 bool ConstantFolded =
false;
151 Src0.ChangeToImmediate(MovSrc.
getImm());
152 ConstantFolded =
true;
153 }
else if (MovSrc.
isFI()) {
155 Src0.ChangeToFrameIndex(MovSrc.
getIndex());
156 ConstantFolded =
true;
159 if (ConstantFolded) {
162 ++NumLiteralConstantsFolded;
171 if (TII->commuteInstruction(MI)) {
176 TII->commuteInstruction(MI);
188 if (
Use.isUse() &&
Use.getReg() == AMDGPU::VCC) {
228 int32_t &ReverseImm) {
232 ReverseImm = reverseBits<int32_t>(
static_cast<int32_t
>(Src.
getImm()));
233 return ReverseImm >= -16 && ReverseImm <= 64;
254 TII->commuteInstruction(MI,
false, 0, 1);
266 if (SOPKOpc == AMDGPU::S_CMPK_EQ_U32 || SOPKOpc == AMDGPU::S_CMPK_LG_U32) {
270 SOPKOpc = (SOPKOpc == AMDGPU::S_CMPK_EQ_U32) ?
271 AMDGPU::S_CMPK_EQ_I32 : AMDGPU::S_CMPK_LG_I32;
297 std::vector<unsigned> I1Defs;
304 for (I = MBB.
begin(); I != MBB.
end(); I = Next) {
308 if (MI.
getOpcode() == AMDGPU::V_MOV_B32_e32) {
322 MI.
setDesc(TII->get(AMDGPU::V_BFREV_B32_e32));
338 (*Next).getOpcode() == AMDGPU::S_NOP) {
348 if (Nop0 + Nop1 <= 8) {
361 if (MI.
getOpcode() == AMDGPU::S_ADD_I32 ||
368 if (TII->commuteInstruction(MI,
false, 1, 2))
384 unsigned Opc = (MI.
getOpcode() == AMDGPU::S_ADD_I32) ?
385 AMDGPU::S_ADDK_I32 : AMDGPU::S_MULK_I32;
400 if (MI.
getOpcode() == AMDGPU::S_MOV_B32) {
408 MI.
setDesc(TII->get(AMDGPU::S_MOVK_I32));
410 MI.
setDesc(TII->get(AMDGPU::S_BREV_B32));
418 if (!TII->hasVALU32BitEncoding(MI.
getOpcode()))
424 if (!MI.
isCommutable() || !TII->commuteInstruction(MI) ||
431 if (!TII->hasVALU32BitEncoding(MI.
getOpcode()))
436 if (TII->isVOPC(Op32)) {
450 if (DstReg != AMDGPU::VCC)
454 if (Op32 == AMDGPU::V_CNDMASK_B32_e32) {
458 TII->getNamedOperand(MI, AMDGPU::OpName::src2);
461 unsigned SReg = Src2->
getReg();
466 if (SReg != AMDGPU::VCC)
472 AMDGPU::OpName::sdst);
476 AMDGPU::OpName::src2);
479 if (SDst->
getReg() != AMDGPU::VCC) {
487 if (Src2 && Src2->
getReg() != AMDGPU::VCC) {
504 if (Op32DstIdx != -1) {
513 Inst32.
add(*TII->getNamedOperand(MI, AMDGPU::OpName::src0));
516 TII->getNamedOperand(MI, AMDGPU::OpName::src1);
522 if (Op32Src2Idx != -1) {
532 ++NumInstructionsShrunk;
540 DEBUG(
dbgs() <<
"e32 MI = " << *Inst32 <<
'\n');
constexpr bool isUInt< 32 >(uint64_t x)
static bool isReverseInlineImm(const SIInstrInfo *TII, const MachineOperand &Src, int32_t &ReverseImm)
unsigned getNumImplicitUses() const
Return the number of implicit uses this instruction has.
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
AMDGPU specific subclass of TargetSubtarget.
static bool canShrink(MachineInstr &MI, const SIInstrInfo *TII, const SIRegisterInfo &TRI, const MachineRegisterInfo &MRI)
static bool sopkIsZext(const MachineInstr &MI)
unsigned getNumImplicitDefs() const
Return the number of implicit defs this instruct has.
Describe properties that are true of each instruction in the target description file.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const SIInstrInfo * getInstrInfo() const override
unsigned getOperandNo(const_mop_iterator I) const
Returns the number of the operand iterator I points to.
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
constexpr bool isInt< 16 >(int64_t x)
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
static void copyFlagsToImplicitVCC(MachineInstr &MI, const MachineOperand &Orig)
LLVM_READONLY int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIdx)
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
A Use represents the edge between a Value definition and its users.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
LLVM_READONLY MachineOperand * getNamedOperand(MachineInstr &MI, unsigned OperandName) const
Returns the operand named Op.
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
Reg
All possible values of the reg field in the ModR/M byte.
static bool isVGPR(const MachineOperand *MO, const SIRegisterInfo &TRI, const MachineRegisterInfo &MRI)
static bool isKImmOrKUImmOperand(const SIInstrInfo *TII, const MachineOperand &Src, bool &IsUnsigned)
unsigned getNumOperands() const
Access to explicit operands of the instruction.
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
#define DEBUG_TYPE
The pass tries to use the 32-bit encoding for instructions when possible.
static bool isKUImmOperand(const SIInstrInfo *TII, const MachineOperand &Src)
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
STATISTIC(NumInstructionsShrunk,"Number of 64-bit instruction reduced to 32-bit.")
unsigned const MachineRegisterInfo * MRI
static void shrinkScalarCompare(const SIInstrInfo *TII, MachineInstr &MI)
bool hasVGPRs(const TargetRegisterClass *RC) const
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const MachineOperand & getOperand(unsigned i) const
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Represent the analysis usage information of a pass.
LLVM_READONLY int getSOPKOp(uint16_t Opcode)
void setImm(int64_t immVal)
FunctionPass class - This class is used to implement most global optimizations.
static bool isVOP2(const MachineInstr &MI)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
bool isRegMask() const
isRegMask - Tests if this is a MO_RegisterMask operand.
bool isInlineConstant(const APInt &Imm) const
Iterator for intrusive lists based on ilist_node.
void setDesc(const MCInstrDesc &tid)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one...
constexpr bool isInt< 32 >(int64_t x)
void addOperand(MachineFunction &MF, const MachineOperand &Op)
Add the specified operand to the instruction.
LLVM_READONLY int getVOPe32(uint16_t Opcode)
MachineOperand class - Representation of each machine instruction operand.
void setRegAllocationHint(unsigned VReg, unsigned Type, unsigned PrefReg)
setRegAllocationHint - Specify a register allocation hint for the specified virtual register...
bool hasOneUse(unsigned RegNo) const
hasOneUse - Return true if there is exactly one instruction using the specified register.
static bool isKImmOperand(const SIInstrInfo *TII, const MachineOperand &Src)
void setPreservesCFG()
This function should be called by the pass, iff they do not:
bool isCompare(QueryType Type=IgnoreBundle) const
Return true if this instruction is a comparison.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
iterator_range< mop_iterator > implicit_operands()
MachineInstr * getUniqueVRegDef(unsigned Reg) const
getUniqueVRegDef - Return the unique machine instr that defines the specified virtual register or nul...
const TargetRegisterClass * getPhysRegClass(unsigned Reg) const
Return the 'base' register class for this register.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Representation of each machine instruction.
static void copyExtraImplicitOps(MachineInstr &NewMI, MachineFunction &MF, const MachineInstr &MI)
Copy implicit register operands from specified instruction to this instruction that are not part of t...
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
Interface definition for SIInstrInfo.
FunctionPass * createSIShrinkInstructionsPass()
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
static bool isVOPC(const MachineInstr &MI)
void setSubReg(unsigned subReg)
constexpr bool isUInt< 16 >(uint64_t x)
unsigned getReg() const
getReg - Returns the register number.
bool isCommutable(QueryType Type=IgnoreBundle) const
Return true if this may be a 2- or 3-address instruction (of the form "X = op Y, Z, ..."), which produces the same result if Y and Z are exchanged.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool hasModifiersSet(const MachineInstr &MI, unsigned OpName) const
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
StringRef - Represent a constant reference to a string, i.e.
bool isMoveImmediate(QueryType Type=IgnoreBundle) const
Return true if this instruction is a move immediate (including conditional moves) instruction...
static bool isVOP1(const MachineInstr &MI)
static bool foldImmediates(MachineInstr &MI, const SIInstrInfo *TII, MachineRegisterInfo &MRI, bool TryToCommute=true)
This function checks MI for operands defined by a move immediate instruction and then folds the liter...
bool use_empty(unsigned RegNo) const
use_empty - Return true if there are no instructions using the specified register.
void tieOperands(unsigned DefIdx, unsigned UseIdx)
Add a tie between the register operands at DefIdx and UseIdx.