64#define DEBUG_TYPE "hexagon-peephole"
79 return "Hexagon optimize redundant zero and size extends";
88char HexagonPeephole::ID = 0;
94 if (skipFunction(MF.getFunction()))
99 QII =
static_cast<const HexagonInstrInfo *
>(MF.getSubtarget().getInstrInfo());
100 MRI = &MF.getRegInfo();
104 DenseMap<
unsigned, std::pair<unsigned, unsigned> > PeepholeDoubleRegsMap;
106 if (!CLOpts.opt_peephole)
112 PeepholeDoubleRegsMap.clear();
118 if (CLOpts.optszext &&
MI.getOpcode() == Hexagon::A2_sxtw) {
129 PeepholeMap[DstReg] = SrcReg;
135 if (CLOpts.opt_ext_to_64 &&
MI.getOpcode() == Hexagon::A4_combineir) {
140 if (Src1.getImm() != 0)
144 PeepholeMap[DstReg] = SrcReg;
152 if (
MI.getOpcode() == Hexagon::S2_lsr_i_p) {
157 if (Src2.getImm() != 32)
161 PeepholeDoubleRegsMap[DstReg] =
162 std::make_pair(*&SrcReg, Hexagon::isub_hi);
166 if (CLOpts.pnotp &&
MI.getOpcode() == Hexagon::C2_not) {
177 PeepholeMap[DstReg] = SrcReg;
183 if (CLOpts.optszext &&
MI.isCopy()) {
189 if (Src.getSubReg() != Hexagon::isub_lo)
196 if (
unsigned PeepholeSrc = PeepholeMap.lookup(SrcReg)) {
203 PeepholeDoubleRegsMap.find(SrcReg);
204 if (DI != PeepholeDoubleRegsMap.
end()) {
205 std::pair<unsigned,unsigned> PeepholeSrc = DI->second;
208 PeepholeSrc.first,
false ,
false ,
209 false ,
false ,
false ,
210 false , PeepholeSrc.second));
220 if (QII->isPredicated(
MI)) {
224 if (RC0->
getID() == Hexagon::PredRegsRegClassID) {
229 if (
unsigned PeepholeSrc = PeepholeMap.lookup(Reg0)) {
231 MI.getOperand(0).setReg(PeepholeSrc);
232 int NewOp = QII->getInvertedPredicatedOpcode(
MI.getOpcode());
233 MI.setDesc(QII->get(NewOp));
243 unsigned Op =
MI.getOpcode();
245 unsigned PR = 1,
S1 = 2, S2 = 3;
248 case Hexagon::C2_mux:
249 case Hexagon::C2_muxii:
252 case Hexagon::C2_muxri:
253 NewOp = Hexagon::C2_muxir;
255 case Hexagon::C2_muxir:
256 NewOp = Hexagon::C2_muxri;
261 if (
unsigned POrig = PeepholeMap.lookup(PSrc)) {
263 MI.getOperand(0).getReg())
265 .
add(
MI.getOperand(S2))
267 MI.eraseFromParent();
278 if (CLOpts.fuse_intrinsic_vminub)
279 Changed |= fuseIntrinsicVMinUB(MF);
286 auto I1Uses = I1.explicit_uses();
288 unsigned I1NumUses = I1.getNumExplicitOperands() - I1.getNumExplicitDefs();
290 if (!I1NumUses || I1NumUses != I2NumUses)
293 auto I2Use = I2Uses.begin();
295 if (!I1Use.isIdenticalTo(*I2Use++))
313 for (MachineBasicBlock &
MBB : MF) {
314 SmallPtrSet<MachineInstr *, 8> DeadMIs;
316 for (MachineInstr &
MI :
MBB) {
317 unsigned Opc =
MI.getOpcode();
318 if ((
Opc != Hexagon::A2_vminub &&
Opc != Hexagon::C2_cmpgtup) ||
322 unsigned SiblingOpc =
323 Opc == Hexagon::A2_vminub ? Hexagon::C2_cmpgtup : Hexagon::A2_vminub;
325 for (
const MachineOperand &MO :
MI.operands())
326 if (MO.isReg() && !MO.isDef() && MO.getReg().isPhysical())
328 MachineInstr *Sibling =
nullptr;
329 auto It =
MI.getIterator();
330 for (++It; It !=
MBB.
end(); ++It) {
331 if (!DeadMIs.
count(&*It) && It->getOpcode() == SiblingOpc &&
342 MachineInstr *VMin =
Opc == Hexagon::A2_vminub ? &
MI : Sibling;
343 MachineInstr *
Cmp =
Opc == Hexagon::A2_vminub ? Sibling : &
MI;
349 QII->get(Hexagon::A6_vminub_RdP), VMinReg)
350 .
addReg(CmpReg, RegState::Define)
357 "vminub fusion requires virtual result registers");
361 Cmp->getOperand(0).setReg(CmpDef);
368 for (MachineInstr *
MI : DeadMIs)
369 MI->eraseFromParent();
376 return new HexagonPeephole();
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the DenseMap class.
static bool modifiesPhysicalInput(ArrayRef< Register > Inputs, const MachineInstr &Between, const TargetRegisterInfo *TRI)
static bool hasCommonInputOps(const MachineInstr &I1, const MachineInstr &I2)
Register const TargetRegisterInfo * TRI
Promote Memory to Register
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
MachineRegisterInfo & MRI
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
Represent the analysis usage information of a pass.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
FunctionPass class - This class is used to implement most global optimizations.
const HexagonOptions & getCLOpts() const
unsigned getID() const
getID() - Return the register class ID number.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
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.
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
Representation of each machine instruction.
LLVM_ABI unsigned getNumExplicitOperands() const
Returns the number of non-implicit operands.
bool modifiesRegister(Register Reg, const TargetRegisterInfo *TRI) const
Return true if the MachineInstr modifies (fully define or partially define) the specified register.
mop_range explicit_uses()
LLVM_ABI unsigned getNumExplicitDefs() const
Returns the number of non-implicit definitions.
const MachineOperand & getOperand(unsigned i) const
MachineOperand class - Representation of each machine instruction operand.
LLVM_ABI void setReg(Register Reg)
Change the register this operand corresponds to.
Register getReg() const
getReg - Returns the register number.
static MachineOperand CreateReg(Register Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false, bool isRenamable=false)
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
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.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
void push_back(const T &Elt)
Represent a constant reference to a string, i.e.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
self_iterator getIterator()
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
FunctionPass * createHexagonPeephole()
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
DWARFExpression::Operation Op
MCRegisterClass TargetRegisterClass