Use dominates(Instruction, Use) in the verifier.
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 1 Jun 2012 21:56:26 +0000 (21:56 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 1 Jun 2012 21:56:26 +0000 (21:56 +0000)
This removes a bit of context from the verifier erros, but reduces code
duplication in a fairly critical part of LLVM and makes dominates easier to test.

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

lib/VMCore/Verifier.cpp
test/Verifier/dominates.ll

index 7afe342899f0f4f0adb640f8429738c8c746b2d7..4d33c623af5031afdcb3fa2c9b22ef165355f5c8 100644 (file)
@@ -1575,53 +1575,9 @@ void Verifier::visitLandingPadInst(LandingPadInst &LPI) {
 
 void Verifier::verifyDominatesUse(Instruction &I, unsigned i) {
   Instruction *Op = cast<Instruction>(I.getOperand(i));
-  BasicBlock *BB = I.getParent();
-  BasicBlock *OpBlock = Op->getParent();
-  PHINode *PN = dyn_cast<PHINode>(&I);
-
-  // DT can handle non phi instructions for us.
-  if (!PN) {
-    // Definition must dominate use unless use is unreachable!
-    Assert2(InstsInThisBlock.count(Op) || !DT->isReachableFromEntry(BB) ||
-            DT->dominates(Op, &I),
-            "Instruction does not dominate all uses!", Op, &I);
-    return;
-  }
-
-  // Check that a definition dominates all of its uses.
-  if (InvokeInst *II = dyn_cast<InvokeInst>(Op)) {
-    // Invoke results are only usable in the normal destination, not in the
-    // exceptional destination.
-    BasicBlock *NormalDest = II->getNormalDest();
-
-
-    // PHI nodes differ from other nodes because they actually "use" the
-    // value in the predecessor basic blocks they correspond to.
-    BasicBlock *UseBlock = BB;
-    unsigned j = PHINode::getIncomingValueNumForOperand(i);
-    UseBlock = PN->getIncomingBlock(j);
-    Assert2(UseBlock, "Invoke operand is PHI node with bad incoming-BB",
-            Op, &I);
-
-    if (UseBlock == OpBlock) {
-      // Special case of a phi node in the normal destination or the unwind
-      // destination.
-      Assert2(BB == NormalDest || !DT->isReachableFromEntry(UseBlock),
-              "Invoke result not available in the unwind destination!",
-              Op, &I);
-    } else {
-      Assert2(DT->dominates(II, UseBlock) ||
-              !DT->isReachableFromEntry(UseBlock),
-              "Invoke result does not dominate all uses!", Op, &I);
-    }
-  }
 
-  // PHI nodes are more difficult than other nodes because they actually
-  // "use" the value in the predecessor basic blocks they correspond to.
-  unsigned j = PHINode::getIncomingValueNumForOperand(i);
-  BasicBlock *PredBB = PN->getIncomingBlock(j);
-  Assert2(PredBB && (DT->dominates(OpBlock, PredBB) ||
-                     !DT->isReachableFromEntry(PredBB)),
+  const Use &U = I.getOperandUse(i);
+  Assert2(InstsInThisBlock.count(Op) || DT->dominates(Op, U),
           "Instruction does not dominate all uses!", Op, &I);
 }
 
index 21aa7f6cd3840ed2ee37c348ca6f537dde2e9e74..50bfa616f0dcc93eab0fb2b7818290eb2335b9cf 100644 (file)
@@ -20,7 +20,7 @@ bb2:
   %y3 = landingpad i32 personality i32 ()* @g
           cleanup
   ret void
-; CHECK: Invoke result not available in the unwind destination!
+; CHECK: Instruction does not dominate all uses!
 ; CHECK-NEXT:  %y1 = invoke i32 @g()
 ; CHECK-NEXT:        to label %bb1 unwind label %bb2
 ; CHECK-NEXT:  %y2 = phi i32 [ %y1, %bb0 ]
@@ -38,7 +38,7 @@ bb2:
 bb3:
   %y3 = phi i32 [%y1, %bb2]
   ret void
-; CHECK: Invoke result does not dominate all uses!
+; CHECK: Instruction does not dominate all uses!
 ; CHECK-NEXT:  %y1 = invoke i32 @g()
 ; CHECK-NEXT:          to label %bb1 unwind label %bb2
 ; CHECK-NEXT:  %y3 = phi i32 [ %y1, %bb2 ]