Fix an invalid bitcast crash that occurs when doing a partial memset of a vector

alloca. Fixes part of <rdar://problem/9580800>.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@133336 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Cameron Zwarich
2011-06-18 05:47:49 +00:00
parent aab3ea244c
commit 6be41eb7f0
2 changed files with 37 additions and 3 deletions

View File

@@ -521,10 +521,22 @@ bool ConvertToScalarInfo::CanConvertToScalar(Value *V, uint64_t Offset) {
// If this is a constant sized memset of a constant value (e.g. 0) we can
// handle it.
if (MemSetInst *MSI = dyn_cast<MemSetInst>(User)) {
// Store of constant value and constant size.
if (!isa<ConstantInt>(MSI->getValue()) ||
!isa<ConstantInt>(MSI->getLength()))
// Store of constant value.
if (!isa<ConstantInt>(MSI->getValue()))
return false;
// Store of constant size.
ConstantInt *Len = dyn_cast<ConstantInt>(MSI->getLength());
if (!Len)
return false;
// If the size differs from the alloca, we can only convert the alloca to
// an integer bag-of-bits.
// FIXME: This should handle all of the cases that are currently accepted
// as vector element insertions.
if (Len->getZExtValue() != AllocaSize || Offset != 0)
ScalarKind = Integer;
IsNotTrivial = true; // Can't be mem2reg'd.
HadNonMemTransferAccess = true;
continue;