Skip to content

Commit c598ef7

Browse files
committed
SimpleLoopUnswitch - fix uninitialized variable and null dereference warnings. NFCI.
llvm-svn: 374986
1 parent b13d257 commit c598ef7

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,7 +1909,7 @@ static void unswitchNontrivialInvariants(
19091909

19101910
// We can only unswitch switches, conditional branches with an invariant
19111911
// condition, or combining invariant conditions with an instruction.
1912-
assert((SI || BI->isConditional()) &&
1912+
assert((SI || (BI && BI->isConditional())) &&
19131913
"Can only unswitch switches and conditional branch!");
19141914
bool FullUnswitch = SI || BI->getCondition() == Invariants[0];
19151915
if (FullUnswitch)
@@ -2724,7 +2724,7 @@ unswitchBestCondition(Loop &L, DominatorTree &DT, LoopInfo &LI,
27242724
return Cost * (SuccessorsCount - 1);
27252725
};
27262726
Instruction *BestUnswitchTI = nullptr;
2727-
int BestUnswitchCost;
2727+
int BestUnswitchCost = 0;
27282728
ArrayRef<Value *> BestUnswitchInvariants;
27292729
for (auto &TerminatorAndInvariants : UnswitchCandidates) {
27302730
Instruction &TI = *TerminatorAndInvariants.first;
@@ -2756,6 +2756,7 @@ unswitchBestCondition(Loop &L, DominatorTree &DT, LoopInfo &LI,
27562756
BestUnswitchInvariants = Invariants;
27572757
}
27582758
}
2759+
assert(BestUnswitchTI && "Failed to find loop unswitch candidate");
27592760

27602761
if (BestUnswitchCost >= UnswitchThreshold) {
27612762
LLVM_DEBUG(dbgs() << "Cannot unswitch, lowest cost found: "

0 commit comments

Comments
 (0)