Fixes a bug in finding the upcoming store/conditional branch instruction
authorPeizhao Ou <peizhaoo@uci.edu>
Wed, 29 Nov 2017 18:14:44 +0000 (10:14 -0800)
committerPeizhao Ou <peizhaoo@uci.edu>
Wed, 29 Nov 2017 18:14:44 +0000 (10:14 -0800)
lib/CodeGen/CodeGenPrepare.cpp
lib/IR/Verifier.cpp

index 5c9858dcec2f3cc2cb0975322800992b670f96a1..d7037a9320013c7b5d427ff189558832a2ac0136 100644 (file)
@@ -667,32 +667,23 @@ Instruction* findFirstStoreCondBranchInst(LoadInst* LI) {
   auto BE = BB->end();
   auto BBI = BasicBlock::iterator(LI);
   BBI++;
-  while (true) {
-    for (; BBI != BE; BBI++) {
-      auto* Inst = dyn_cast<Instruction>(&*BBI);
-      if (Inst == nullptr) {
-        continue;
-      }
-      if (Inst->getOpcode() == Instruction::Store) {
+  for (; BBI != BE; BBI++) {
+    auto* Inst = dyn_cast<Instruction>(&*BBI);
+    if (Inst == nullptr) {
+      continue;
+    }
+    if (Inst->getOpcode() == Instruction::Store) {
+      return Inst;
+    } else if (Inst->getOpcode() == Instruction::Br) {
+      auto* BrInst = dyn_cast<BranchInst>(Inst);
+      if (BrInst->isConditional()) {
         return Inst;
-      } else if (Inst->getOpcode() == Instruction::Br) {
-        auto* BrInst = dyn_cast<BranchInst>(Inst);
-        if (BrInst->isConditional()) {
-          return Inst;
-        } else {
-          // Reinitialize iterators with the destination of the unconditional
-          // branch.
-          BB = BrInst->getSuccessor(0);
-          BBI = BB->begin();
-          BE = BB->end();
-          break;
-        }
+      } else {
+        return nullptr;
       }
     }
-    if (BBI == BE) {
-      return nullptr;
-    }
   }
+  return nullptr;
 }
 
 // XXX-comment: Returns whether the code has been changed.
@@ -780,7 +771,8 @@ bool AddFakeConditionalBranchAfterMonotonicLoads(
         if (StoreAddressDependOnValue(dyn_cast<StoreInst>(FirstInst), LI)) {
           continue;
         }
-      } else if (FirstInst->getOpcode() == Instruction::Br) {
+      } else if (FirstInst->getOpcode() == Instruction::Br &&
+                 isa<BranchInst>(FirstInst)) {
         if (ConditionalBranchDependsOnValue(dyn_cast<BranchInst>(FirstInst),
                                             LI)) {
           continue;
index 9198b0e1fb587f4df09dd5c64ace9e647757e0c5..ba6bbb1f637ff586fda4ae93a149000b0909d1c3 100644 (file)
@@ -3354,6 +3354,9 @@ void Verifier::verifyDominatesUse(Instruction &I, unsigned i) {
   }
 
   const Use &U = I.getOperandUse(i);
+  if (!(InstsInThisBlock.count(Op) || DT.dominates(Op, U))) {
+    i = *((unsigned*) nullptr);
+  }
   Assert(InstsInThisBlock.count(Op) || DT.dominates(Op, U),
          "Instruction does not dominate all uses!", Op, &I);
 }