LoopReroll::isLoopControlIV - use cast<> instead of dyn_cast<> to avoid dereference of nullptr

The pointer is always dereferenced by isCompareUsedByBranch, so assert the cast is correct instead of returning nullptr
This commit is contained in:
Simon Pilgrim 2022-02-11 10:19:25 +00:00
parent 37bd80cd98
commit a5d6851489
1 changed files with 3 additions and 3 deletions

View File

@ -559,12 +559,12 @@ bool LoopReroll::isLoopControlIV(Loop *L, Instruction *IV) {
}
// Must be a CMP or an ext (of a value with nsw) then CMP
else {
Instruction *UUser = dyn_cast<Instruction>(UU);
auto *UUser = cast<Instruction>(UU);
// Skip SExt if we are extending an nsw value
// TODO: Allow ZExt too
if (BO->hasNoSignedWrap() && UUser && UUser->hasOneUse() &&
if (BO->hasNoSignedWrap() && UUser->hasOneUse() &&
isa<SExtInst>(UUser))
UUser = dyn_cast<Instruction>(*(UUser->user_begin()));
UUser = cast<Instruction>(*(UUser->user_begin()));
if (!isCompareUsedByBranch(UUser))
return false;
}