-/// IsGuaranteedToExecute - check to make sure that the instruction dominates
-/// all of the exit blocks. If it doesn't, then there is a path out of the loop
-/// which does not execute this instruction, so we can't hoist it.
-bool MachineLICM::IsGuaranteedToExecute(MachineInstr *MI) {
- // If the instruction is in the header block for the loop (which is very
- // common), it is always guaranteed to dominate the exit blocks. Since this
- // is a common case, and can save some work, check it now.
- if (MI->getParent() == CurLoop->getHeader())
- return true;
-
- // Get the exit blocks for the current loop.
- SmallVector<MachineBasicBlock*, 8> ExitBlocks;
- CurLoop->getExitingBlocks(ExitBlocks);
-
- // Verify that the block dominates each of the exit blocks of the loop.
- for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i)
- if (ExitBlocks[i] != CurLoop->getHeader() &&
- !DT->dominates(MI->getParent(), ExitBlocks[i]))
- 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;