llvm.org GIT mirror llvm / 24dbb79
Peephole opt needs optimizeSelect() to keep track of newly created MIs Peephole optimizer is scanning a basic block forward. At some point it needs to answer the question "given a pointer to an MI in the current BB, is it located before or after the current instruction". To perform this, it keeps a set of the MIs already seen during the scan, if a MI is not in the set, it is assumed to be after. It means that newly created MIs have to be inserted in the set as well. This commit passes the set as an argument to the target-dependent optimizeSelect() so that it can properly update the set with the (potentially) newly created MIs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225772 91177308-0d34-0410-b5e6-96231b3b80d8 Mehdi Amini 5 years ago
4 changed file(s) with 27 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
602602 /// a side.
603603 ///
604604 /// @param MI Optimizable select instruction.
605 /// @param SeenMIs Set that record all MIs in the basic block up to \p
606 /// MI. Has to be updated with any newly created MI or deleted ones.
605607 /// @param PreferFalse Try to optimize FalseOp instead of TrueOp.
606608 /// @returns Optimized instruction or NULL.
607609 virtual MachineInstr *optimizeSelect(MachineInstr *MI,
610 SmallPtrSetImpl &NewMIs,
608611 bool PreferFalse = false) const {
609612 // This function must be implemented if Optimizable is ever set.
610613 llvm_unreachable("Target must implement TargetInstrInfo::optimizeSelect!");
132132 bool optimizeCmpInstr(MachineInstr *MI, MachineBasicBlock *MBB);
133133 bool optimizeExtInstr(MachineInstr *MI, MachineBasicBlock *MBB,
134134 SmallPtrSetImpl &LocalMIs);
135 bool optimizeSelect(MachineInstr *MI);
135 bool optimizeSelect(MachineInstr *MI,
136 SmallPtrSetImpl &LocalMIs);
136137 bool optimizeCondBranch(MachineInstr *MI);
137138 bool optimizeCopyOrBitcast(MachineInstr *MI);
138139 bool optimizeCoalescableCopy(MachineInstr *MI);
481482 }
482483
483484 /// Optimize a select instruction.
484 bool PeepholeOptimizer::optimizeSelect(MachineInstr *MI) {
485 bool PeepholeOptimizer::optimizeSelect(MachineInstr *MI,
486 SmallPtrSetImpl &LocalMIs) {
485487 unsigned TrueOp = 0;
486488 unsigned FalseOp = 0;
487489 bool Optimizable = false;
490492 return false;
491493 if (!Optimizable)
492494 return false;
493 if (!TII->optimizeSelect(MI))
495 if (!TII->optimizeSelect(MI, LocalMIs))
494496 return false;
495497 MI->eraseFromParent();
496498 ++NumSelects;
10711073 MachineBasicBlock *MBB = &*I;
10721074
10731075 bool SeenMoveImm = false;
1076
1077 // During this forward scan, at some point it needs to answer the question
1078 // "given a pointer to an MI in the current BB, is it located before or
1079 // after the current instruction".
1080 // To perform this, the following set keeps track of the MIs already seen
1081 // during the scan, if a MI is not in the set, it is assumed to be located
1082 // after. Newly created MIs have to be inserted in the set as well.
10741083 SmallPtrSet LocalMIs;
10751084 SmallSet ImmDefRegs;
10761085 DenseMap ImmDefMIs;
11011110 if ((isUncoalescableCopy(*MI) &&
11021111 optimizeUncoalescableCopy(MI, LocalMIs)) ||
11031112 (MI->isCompare() && optimizeCmpInstr(MI, MBB)) ||
1104 (MI->isSelect() && optimizeSelect(MI))) {
1113 (MI->isSelect() && optimizeSelect(MI, LocalMIs))) {
11051114 // MI is deleted.
11061115 LocalMIs.erase(MI);
11071116 Changed = true;
18351835 return false;
18361836 }
18371837
1838 MachineInstr *ARMBaseInstrInfo::optimizeSelect(MachineInstr *MI,
1839 bool PreferFalse) const {
1838 MachineInstr *
1839 ARMBaseInstrInfo::optimizeSelect(MachineInstr *MI,
1840 SmallPtrSetImpl &SeenMIs,
1841 bool PreferFalse) const {
18401842 assert((MI->getOpcode() == ARM::MOVCCr || MI->getOpcode() == ARM::t2MOVCCr) &&
18411843 "Unknown select instruction");
18421844 MachineRegisterInfo &MRI = MI->getParent()->getParent()->getRegInfo();
18831885 FalseReg.setImplicit();
18841886 NewMI.addOperand(FalseReg);
18851887 NewMI->tieOperands(0, NewMI->getNumOperands() - 1);
1888
1889 // Update SeenMIs set: register newly created MI and erase removed DefMI.
1890 SeenMIs.insert(NewMI);
1891 SeenMIs.erase(DefMI);
18861892
18871893 // The caller will erase MI, but not DefMI.
18881894 DefMI->eraseFromParent();
260260 unsigned &TrueOp, unsigned &FalseOp,
261261 bool &Optimizable) const override;
262262
263 MachineInstr *optimizeSelect(MachineInstr *MI, bool) const override;
263 MachineInstr *optimizeSelect(MachineInstr *MI,
264 SmallPtrSetImpl &SeenMIs,
265 bool) const override;
264266
265267 /// FoldImmediate - 'Reg' is known to be defined by a move immediate
266268 /// instruction, try to fold the immediate into the use instruction.