[SCEVExpander] GetOptimalInsertionPointForCastOf(): gracefully handle Constant's

I guess this case hasn't come up thus far, and i'm not sure if it can
really happen for the existing usages, thus no test in *this* commit.

But, the following commit adds test coverage,
there we'd expirience a crash without this fix.
This commit is contained in:
Roman Lebedev 2021-04-19 17:36:20 +03:00
parent b8a3705896
commit 442c408e0e
No known key found for this signature in database
GPG Key ID: 083C3EBB4A1689E0
1 changed files with 11 additions and 2 deletions

View File

@ -130,8 +130,17 @@ SCEVExpander::GetOptimalInsertionPointForCastOf(Value *V) const {
}
// Cast the instruction immediately after the instruction.
Instruction *I = cast<Instruction>(V);
return findInsertPointAfter(I, &*Builder.GetInsertPoint());
if (Instruction *I = dyn_cast<Instruction>(V))
return findInsertPointAfter(I, &*Builder.GetInsertPoint());
// Otherwise, this must be some kind of a constant,
// so let's plop this cast into the function's entry block.
assert(isa<Constant>(V) &&
"Expected the cast argument to be a global/constant");
return Builder.GetInsertBlock()
->getParent()
->getEntryBlock()
.getFirstInsertionPt();
}
/// InsertNoopCastOfTo - Insert a cast of V to the specified type,