diff options
author | Evan Cheng <evan.cheng@apple.com> | 2011-10-12 00:09:14 +0000 |
---|---|---|
committer | Evan Cheng <evan.cheng@apple.com> | 2011-10-12 00:09:14 +0000 |
commit | 7efba85d414949febe51100e298077233526787c (patch) | |
tree | 38f1da200c4c67544f0ce37508048cbf30946980 | |
parent | 1c062c24aba08962b4687f56b274f182e5b7a8e5 (diff) |
Fix r141744.
1. The speculation check may not have been performed if the BB hasn't had a load
LICM candidate.
2. If the candidate would be CSE'ed, then go ahead and speculatively LICM the
instruction even if it's in high register pressure situation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141747 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/MachineLICM.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/CodeGen/MachineLICM.cpp b/lib/CodeGen/MachineLICM.cpp index 63c73d2e4e..6116281d59 100644 --- a/lib/CodeGen/MachineLICM.cpp +++ b/lib/CodeGen/MachineLICM.cpp @@ -251,6 +251,10 @@ namespace { bool EliminateCSE(MachineInstr *MI, DenseMap<unsigned, std::vector<const MachineInstr*> >::iterator &CI); + /// MayCSE - Return true if the given instruction will be CSE'd if it's + /// hoisted out of the loop. + bool MayCSE(MachineInstr *MI); + /// Hoist - When an instruction is found to only use loop invariant operands /// that is safe to hoist, this instruction is called to do the dirty work. /// It returns true if the instruction is hoisted. @@ -1047,7 +1051,7 @@ bool MachineLICM::IsProfitableToHoist(MachineInstr &MI) { // Also, do not "speculate" in high register pressure situation. If an // instruction is not guaranteed to be executed in the loop, it's best to be // conservative. - if (SpeculationState == SpeculateTrue || + if ((!IsGuaranteedToExecute(MI.getParent()) && !MayCSE(&MI)) || (!TII->isTriviallyReMaterializable(&MI, AA) && !MI.isInvariantLoad(AA))) return false; @@ -1183,6 +1187,20 @@ bool MachineLICM::EliminateCSE(MachineInstr *MI, return false; } +/// MayCSE - Return true if the given instruction will be CSE'd if it's +/// hoisted out of the loop. +bool MachineLICM::MayCSE(MachineInstr *MI) { + unsigned Opcode = MI->getOpcode(); + DenseMap<unsigned, std::vector<const MachineInstr*> >::iterator + CI = CSEMap.find(Opcode); + // Do not CSE implicit_def so ProcessImplicitDefs can properly propagate + // the undef property onto uses. + if (CI == CSEMap.end() || MI->isImplicitDef()) + return false; + + return LookForDuplicate(MI, CI->second) != 0; +} + /// Hoist - When an instruction is found to use only loop invariant operands /// that are safe to hoist, this instruction is called to do the dirty work. /// |