If the CPSR is defined by a copy, then we don't want to merge it into an IT
authorBill Wendling <isanbard@gmail.com>
Mon, 10 Oct 2011 22:52:53 +0000 (22:52 +0000)
committerBill Wendling <isanbard@gmail.com>
Mon, 10 Oct 2011 22:52:53 +0000 (22:52 +0000)
block. E.g., if we have:

  movs  r1, r1
  rsb   r1, 0
  movs  r2, r2
  rsb   r2, 0

we don't want this to be converted to:

  movs  r1, r1
  movs  r2, r2
  itt   mi
  rsb   r1, 0
  rsb   r2, 0

PR11107 & <rdar://problem/10259534>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141589 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/ARM/Thumb2ITBlockPass.cpp

index 360ec009e201642d5af34f86880ce45e1f5e6ff6..2bf99bfd5c3dcd046cba9a4cc9da2d5f2491831f 100644 (file)
@@ -124,6 +124,28 @@ Thumb2ITBlockPass::MoveCopyOutOfITBlock(MachineInstr *MI,
   if (Uses.count(DstReg) || Defs.count(SrcReg))
     return false;
 
+  // If the CPSR is defined by this copy, then we don't want to move it. E.g.,
+  // if we have:
+  //
+  //   movs  r1, r1
+  //   rsb   r1, 0
+  //   movs  r2, r2
+  //   rsb   r2, 0
+  //
+  // we don't want this to be converted to:
+  //
+  //   movs  r1, r1
+  //   movs  r2, r2
+  //   itt   mi
+  //   rsb   r1, 0
+  //   rsb   r2, 0
+  //
+  // 
+  for (unsigned I = 0, E = MI->getNumOperands(); I != E; ++I)
+    if (MI->getOperand(I).isReg() && MI->getOperand(I).getReg() == ARM::CPSR &&
+        MI->getOperand(I).isDef())
+      return false;
+
   // Then peek at the next instruction to see if it's predicated on CC or OCC.
   // If not, then there is nothing to be gained by moving the copy.
   MachineBasicBlock::iterator I = MI; ++I;