- // All of the instructions have a single use and have no side-effects,
- // because of this, we can pull them all into the current basic block.
- if (LHSI->getParent() != BB) {
- // Move all of the instructions from root to LHSI into the current
- // block.
- Instruction *TmpLHSI = cast<Instruction>(Root.getOperand(0));
- Instruction *LastUse = &Root;
- while (TmpLHSI->getParent() == BB) {
- LastUse = TmpLHSI;
- TmpLHSI = cast<Instruction>(TmpLHSI->getOperand(0));
- }
-
- // Loop over all of the instructions in other blocks, moving them into
- // the current one.
- Value *TmpLHS = TmpLHSI;
- do {
- TmpLHSI = cast<Instruction>(TmpLHS);
- // Remove from current block...
- TmpLHSI->getParent()->getInstList().remove(TmpLHSI);
- // Insert before the last instruction...
- BB->getInstList().insert(LastUse, TmpLHSI);
- TmpLHS = TmpLHSI->getOperand(0);
- } while (TmpLHSI != LHSI);
- }