Use cast<> instead of dyn_cast<> for things that are known to be
authorJay Foad <jay.foad@gmail.com>
Sat, 6 Jun 2009 17:49:35 +0000 (17:49 +0000)
committerJay Foad <jay.foad@gmail.com>
Sat, 6 Jun 2009 17:49:35 +0000 (17:49 +0000)
Instructions.

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

lib/Transforms/IPO/GlobalOpt.cpp
lib/Transforms/IPO/IPConstantPropagation.cpp
lib/Transforms/Scalar/PredicateSimplifier.cpp
lib/Transforms/Scalar/ScalarReplAggregates.cpp

index 2c01cc30bd69e1363a6f558f9cf35f9457ed6867..5f12825f043aaaa9b98afbeb88e8f4cb83d026dc 100644 (file)
@@ -932,8 +932,7 @@ static bool ValueIsOnlyUsedLocallyOrStoredToOneGlobal(Instruction *V,
                                                       GlobalVariable *GV,
                                               SmallPtrSet<PHINode*, 8> &PHIs) {
   for (Value::use_iterator UI = V->use_begin(), E = V->use_end(); UI != E;++UI){
-    Instruction *Inst = dyn_cast<Instruction>(*UI);
-    if (Inst == 0) return false;
+    Instruction *Inst = cast<Instruction>(*UI);
     
     if (isa<LoadInst>(Inst) || isa<CmpInst>(Inst)) {
       continue; // Fine, ignore.
index 2dc8558246915385a2298a144b17217b07ef7be0..e4a9deadd971ef56181d110862258f56da59f0df 100644 (file)
@@ -241,15 +241,11 @@ bool IPCP::PropagateConstantReturn(Function &F) {
    
     for (Value::use_iterator I = Call->use_begin(), E = Call->use_end();
          I != E;) {
-      Instruction *Ins = dyn_cast<Instruction>(*I);
+      Instruction *Ins = cast<Instruction>(*I);
 
       // Increment now, so we can remove the use
       ++I;
 
-      // Not an instruction? Ignore
-      if (!Ins)
-        continue;
-
       // Find the index of the retval to replace with
       int index = -1;
       if (ExtractValueInst *EV = dyn_cast<ExtractValueInst>(Ins))
index a7e4d6eec443b5a7d051c1bd81caad52e907e7bc..b9b5688dfdf255c6d03a0620f1450f4b56b1bc51 100644 (file)
@@ -1525,12 +1525,12 @@ namespace {
         Instruction *I2 = dyn_cast<Instruction>(R);
         if (I2 && below(I2)) {
           std::vector<Instruction *> ToNotify;
-          for (Value::use_iterator UI = R->use_begin(), UE = R->use_end();
+          for (Value::use_iterator UI = I2->use_begin(), UE = I2->use_end();
                UI != UE;) {
             Use &TheUse = UI.getUse();
             ++UI;
-            if (Instruction *I = dyn_cast<Instruction>(TheUse.getUser()))
-              ToNotify.push_back(I);
+            Instruction *I = cast<Instruction>(TheUse.getUser());
+            ToNotify.push_back(I);
           }
 
           DOUT << "Simply removing " << *I2
@@ -1658,10 +1658,9 @@ namespace {
           ++UI;
           Value *V = TheUse.getUser();
           if (!V->use_empty()) {
-            if (Instruction *Inst = dyn_cast<Instruction>(V)) {
-              if (aboveOrBelow(Inst))
-                opsToDef(Inst);
-            }
+            Instruction *Inst = cast<Instruction>(V);
+            if (aboveOrBelow(Inst))
+              opsToDef(Inst);
           }
         }
       }
@@ -2262,10 +2261,9 @@ namespace {
                    UE = O.LHS->use_end(); UI != UE;) {
                 Use &TheUse = UI.getUse();
                 ++UI;
-                if (Instruction *I = dyn_cast<Instruction>(TheUse.getUser())) {
-                  if (aboveOrBelow(I))
-                    opsToDef(I);
-                }
+                Instruction *I = cast<Instruction>(TheUse.getUser());
+                if (aboveOrBelow(I))
+                  opsToDef(I);
               }
             }
             if (Instruction *I2 = dyn_cast<Instruction>(O.RHS)) {
@@ -2277,10 +2275,9 @@ namespace {
                    UE = O.RHS->use_end(); UI != UE;) {
                 Use &TheUse = UI.getUse();
                 ++UI;
-                if (Instruction *I = dyn_cast<Instruction>(TheUse.getUser())) {
-                  if (aboveOrBelow(I))
-                    opsToDef(I);
-                }
+                Instruction *I = cast<Instruction>(TheUse.getUser());
+                if (aboveOrBelow(I))
+                  opsToDef(I);
               }
             }
           }
index 9935f12f893bf94cb118f5b821261e3d47beef3a..7143c7be485eab9e41249563e7690f074edd9e66 100644 (file)
@@ -1228,7 +1228,8 @@ void SROA::CleanupAllocaUsers(AllocationInst *AI) {
     User *U = *UI++;
     if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(U))
       CleanupGEP(GEPI);
-    else if (Instruction *I = dyn_cast<Instruction>(U)) {
+    else {
+      Instruction *I = cast<Instruction>(U);
       SmallVector<DbgInfoIntrinsic *, 2> DbgInUses;
       if (!isa<StoreInst>(I) && OnlyUsedByDbgInfoIntrinsics(I, &DbgInUses)) {
         // Safe to remove debug info uses.