]> granicus.if.org Git - llvm/commitdiff
SimpleLoopUnswitch - fix uninitialized variable and null dereference warnings. NFCI.
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 16 Oct 2019 10:38:18 +0000 (10:38 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 16 Oct 2019 10:38:18 +0000 (10:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@374986 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/SimpleLoopUnswitch.cpp

index e7621de82ff434f0670e79b7fd30960493502f7a..ac832b9b456711cd8f2dfe4d52910670aa5fcbf7 100644 (file)
@@ -1909,7 +1909,7 @@ static void unswitchNontrivialInvariants(
 
   // We can only unswitch switches, conditional branches with an invariant
   // condition, or combining invariant conditions with an instruction.
-  assert((SI || BI->isConditional()) &&
+  assert((SI || (BI && BI->isConditional())) &&
          "Can only unswitch switches and conditional branch!");
   bool FullUnswitch = SI || BI->getCondition() == Invariants[0];
   if (FullUnswitch)
@@ -2724,7 +2724,7 @@ unswitchBestCondition(Loop &L, DominatorTree &DT, LoopInfo &LI,
     return Cost * (SuccessorsCount - 1);
   };
   Instruction *BestUnswitchTI = nullptr;
-  int BestUnswitchCost;
+  int BestUnswitchCost = 0;
   ArrayRef<Value *> BestUnswitchInvariants;
   for (auto &TerminatorAndInvariants : UnswitchCandidates) {
     Instruction &TI = *TerminatorAndInvariants.first;
@@ -2756,6 +2756,7 @@ unswitchBestCondition(Loop &L, DominatorTree &DT, LoopInfo &LI,
       BestUnswitchInvariants = Invariants;
     }
   }
+  assert(BestUnswitchTI && "Failed to find loop unswitch candidate");
 
   if (BestUnswitchCost >= UnswitchThreshold) {
     LLVM_DEBUG(dbgs() << "Cannot unswitch, lowest cost found: "