+ // If it is not a trapping instruction, it is always safe to hoist.
+ if (!Inst.isTrapping()) return true;
+
+ // Otherwise we have to 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.
+
+ // 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.
+ BasicBlock *LoopHeader = CurLoop->getHeader();
+ if (Inst.getParent() == LoopHeader)
+ return true;
+
+ // Get the Dominator Tree Node for the instruction's basic block.
+ DominatorTree::Node *InstDTNode = DT->getNode(Inst.getParent());
+
+ // Get the exit blocks for the current loop.
+ const std::vector<BasicBlock* > &ExitBlocks = CurLoop->getExitBlocks();