Hexagon: Avoid dereferencing end() in HexagonInstrInfo::InsertBranch
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Wed, 17 Aug 2016 00:34:00 +0000 (00:34 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Wed, 17 Aug 2016 00:34:00 +0000 (00:34 +0000)
llvm-svn: 278878

llvm/lib/Target/Hexagon/HexagonInstrInfo.cpp

index d3c038a..c148b9c 100644 (file)
@@ -582,13 +582,11 @@ unsigned HexagonInstrInfo::InsertBranch(MachineBasicBlock &MBB,
       SmallVector<MachineOperand, 4> Cond;
       auto Term = MBB.getFirstTerminator();
       if (Term != MBB.end() && isPredicated(*Term) &&
-          !analyzeBranch(MBB, NewTBB, NewFBB, Cond, false)) {
-        MachineBasicBlock *NextBB = &*++MBB.getIterator();
-        if (NewTBB == NextBB) {
-          ReverseBranchCondition(Cond);
-          RemoveBranch(MBB);
-          return InsertBranch(MBB, TBB, nullptr, Cond, DL);
-        }
+          !analyzeBranch(MBB, NewTBB, NewFBB, Cond, false) &&
+          MachineFunction::iterator(NewTBB) == ++MBB.getIterator()) {
+        ReverseBranchCondition(Cond);
+        RemoveBranch(MBB);
+        return InsertBranch(MBB, TBB, nullptr, Cond, DL);
       }
       BuildMI(&MBB, DL, get(BOpc)).addMBB(TBB);
     } else if (isEndLoopN(Cond[0].getImm())) {