Turns out AnalyzeBranch can modify the mbb being analyzed. This is a nasty
[oota-llvm.git] / lib / CodeGen / MachineSink.cpp
index ca47af40a81efbdc448bba8b78f402547387dc11..a85a41fbaee8d92c9bc1b3656f36d2a7aa86071b 100644 (file)
@@ -18,7 +18,6 @@
 #include "llvm/Target/TargetRegisterInfo.h"
 #include "llvm/Target/TargetInstrInfo.h"
 #include "llvm/Target/TargetMachine.h"
-#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Debug.h"
@@ -155,7 +154,7 @@ bool MachineSinking::SinkInstruction(MachineInstr *MI, bool &SawStore) {
   
   for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
     const MachineOperand &MO = MI->getOperand(i);
-    if (!MO.isRegister()) continue;  // Ignore non-register operands.
+    if (!MO.isReg()) continue;  // Ignore non-register operands.
     
     unsigned Reg = MO.getReg();
     if (Reg == 0) continue;
@@ -168,6 +167,10 @@ bool MachineSinking::SinkInstruction(MachineInstr *MI, bool &SawStore) {
     } else {
       // Virtual register uses are always safe to sink.
       if (MO.isUse()) continue;
+
+      // If it's not safe to move defs of the register class, then abort.
+      if (!TII->isSafeToMoveRegClassDefs(RegInfo->getRegClass(Reg)))
+        return false;
       
       // FIXME: This picks a successor to sink into based on having one
       // successor that dominates all the uses.  However, there are cases where