mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-12 01:25:10 +00:00
X86 Peephole: fold loads to the source register operand if possible.
Machine CSE and other optimizations can remove instructions so folding is possible at peephole while not possible at ISel. rdar://10554090 and rdar://11873276 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160919 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -78,6 +78,7 @@ STATISTIC(NumReuse, "Number of extension results reused");
|
||||
STATISTIC(NumBitcasts, "Number of bitcasts eliminated");
|
||||
STATISTIC(NumCmps, "Number of compares eliminated");
|
||||
STATISTIC(NumImmFold, "Number of move immediate folded");
|
||||
STATISTIC(NumLoadFold, "Number of loads folded");
|
||||
|
||||
namespace {
|
||||
class PeepholeOptimizer : public MachineFunctionPass {
|
||||
@@ -441,6 +442,7 @@ bool PeepholeOptimizer::runOnMachineFunction(MachineFunction &MF) {
|
||||
SmallPtrSet<MachineInstr*, 8> LocalMIs;
|
||||
SmallSet<unsigned, 4> ImmDefRegs;
|
||||
DenseMap<unsigned, MachineInstr*> ImmDefMIs;
|
||||
SmallSet<unsigned, 4> FoldAsLoadDefRegs;
|
||||
for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
|
||||
MachineBasicBlock *MBB = &*I;
|
||||
|
||||
@@ -448,6 +450,7 @@ bool PeepholeOptimizer::runOnMachineFunction(MachineFunction &MF) {
|
||||
LocalMIs.clear();
|
||||
ImmDefRegs.clear();
|
||||
ImmDefMIs.clear();
|
||||
FoldAsLoadDefRegs.clear();
|
||||
|
||||
bool First = true;
|
||||
MachineBasicBlock::iterator PMII;
|
||||
@@ -489,6 +492,25 @@ bool PeepholeOptimizer::runOnMachineFunction(MachineFunction &MF) {
|
||||
Changed |= foldImmediate(MI, MBB, ImmDefRegs, ImmDefMIs);
|
||||
}
|
||||
|
||||
MachineInstr *DefMI = 0;
|
||||
MachineInstr *FoldMI = TII->optimizeLoadInstr(MI, MRI, FoldAsLoadDefRegs,
|
||||
DefMI);
|
||||
if (FoldMI) {
|
||||
// Update LocalMIs since we replaced MI with FoldMI and deleted DefMI.
|
||||
LocalMIs.erase(MI);
|
||||
LocalMIs.erase(DefMI);
|
||||
LocalMIs.insert(FoldMI);
|
||||
MI->eraseFromParent();
|
||||
DefMI->eraseFromParent();
|
||||
++NumLoadFold;
|
||||
|
||||
// MI is replaced with FoldMI.
|
||||
Changed = true;
|
||||
PMII = FoldMI;
|
||||
MII = llvm::next(PMII);
|
||||
continue;
|
||||
}
|
||||
|
||||
First = false;
|
||||
PMII = MII;
|
||||
++MII;
|
||||
|
Reference in New Issue
Block a user