[llvm] r374986 - SimpleLoopUnswitch - fix uninitialized variable and null dereference warnings. NFCI.

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 16 03:38:18 PDT 2019


Author: rksimon
Date: Wed Oct 16 03:38:18 2019
New Revision: 374986

URL: http://llvm.org/viewvc/llvm-project?rev=374986&view=rev
Log:
SimpleLoopUnswitch - fix uninitialized variable and null dereference warnings. NFCI.

Modified:
    llvm/trunk/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp?rev=374986&r1=374985&r2=374986&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp Wed Oct 16 03:38:18 2019
@@ -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, Dominator
     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, Dominator
       BestUnswitchInvariants = Invariants;
     }
   }
+  assert(BestUnswitchTI && "Failed to find loop unswitch candidate");
 
   if (BestUnswitchCost >= UnswitchThreshold) {
     LLVM_DEBUG(dbgs() << "Cannot unswitch, lowest cost found: "




More information about the llvm-commits mailing list