Be more layout aware here and swap the successor and branch condition
authorEric Christopher <echristo@apple.com>
Thu, 28 Apr 2011 16:52:09 +0000 (16:52 +0000)
committerEric Christopher <echristo@apple.com>
Thu, 28 Apr 2011 16:52:09 +0000 (16:52 +0000)
if it means we get a fallthrough.

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

lib/Target/ARM/ARMFastISel.cpp

index c95b4a80e44c0e41413fc161bb122dffafdae7f0..3e0b755ff84ac1a746655a0993693e31255ab127 100644 (file)
@@ -1132,9 +1132,16 @@ bool ARMFastISel::SelectBranch(const Instruction *I) {
   AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TstOpc))
                   .addReg(CmpReg).addImm(1));
 
+  
+  unsigned CCMode = ARMCC::NE;
+  if (FuncInfo.MBB->isLayoutSuccessor(TBB)) {
+    std::swap(TBB, FBB);
+    CCMode = ARMCC::EQ;
+  }
+
   unsigned BrOpc = isThumb ? ARM::t2Bcc : ARM::Bcc;
   BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(BrOpc))
-                  .addMBB(TBB).addImm(ARMCC::NE).addReg(ARM::CPSR);
+                  .addMBB(TBB).addImm(CCMode).addReg(ARM::CPSR);
   FastEmitBranch(FBB, DL);
   FuncInfo.MBB->addSuccessor(TBB);
   return true;