fix PR8063, a crash in globalopt in the malloc analysis code.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@113109 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2010-09-05 17:20:46 +00:00
parent b76d20969f
commit e971131695
2 changed files with 44 additions and 20 deletions

View File

@ -880,17 +880,18 @@ bool llvm::ComputeMultiple(Value *V, unsigned Base, Value *&Multiple,
} }
Value *Mul0 = NULL; Value *Mul0 = NULL;
Value *Mul1 = NULL; if (ComputeMultiple(Op0, Base, Mul0, LookThroughSExt, Depth+1)) {
bool M0 = ComputeMultiple(Op0, Base, Mul0, if (Constant *Op1C = dyn_cast<Constant>(Op1))
LookThroughSExt, Depth+1); if (Constant *MulC = dyn_cast<Constant>(Mul0)) {
bool M1 = ComputeMultiple(Op1, Base, Mul1, if (Op1C->getType()->getPrimitiveSizeInBits() <
LookThroughSExt, Depth+1); MulC->getType()->getPrimitiveSizeInBits())
Op1C = ConstantExpr::getZExt(Op1C, MulC->getType());
if (Op1C->getType()->getPrimitiveSizeInBits() >
MulC->getType()->getPrimitiveSizeInBits())
MulC = ConstantExpr::getZExt(MulC, Op1C->getType());
if (M0) {
if (isa<Constant>(Op1) && isa<Constant>(Mul0)) {
// V == Base * (Mul0 * Op1), so return (Mul0 * Op1) // V == Base * (Mul0 * Op1), so return (Mul0 * Op1)
Multiple = ConstantExpr::getMul(cast<Constant>(Mul0), Multiple = ConstantExpr::getMul(MulC, Op1C);
cast<Constant>(Op1));
return true; return true;
} }
@ -902,11 +903,19 @@ bool llvm::ComputeMultiple(Value *V, unsigned Base, Value *&Multiple,
} }
} }
if (M1) { Value *Mul1 = NULL;
if (isa<Constant>(Op0) && isa<Constant>(Mul1)) { if (ComputeMultiple(Op1, Base, Mul1, LookThroughSExt, Depth+1)) {
if (Constant *Op0C = dyn_cast<Constant>(Op0))
if (Constant *MulC = dyn_cast<Constant>(Mul1)) {
if (Op0C->getType()->getPrimitiveSizeInBits() <
MulC->getType()->getPrimitiveSizeInBits())
Op0C = ConstantExpr::getZExt(Op0C, MulC->getType());
if (Op0C->getType()->getPrimitiveSizeInBits() >
MulC->getType()->getPrimitiveSizeInBits())
MulC = ConstantExpr::getZExt(MulC, Op0C->getType());
// V == Base * (Mul1 * Op0), so return (Mul1 * Op0) // V == Base * (Mul1 * Op0), so return (Mul1 * Op0)
Multiple = ConstantExpr::getMul(cast<Constant>(Mul1), Multiple = ConstantExpr::getMul(MulC, Op0C);
cast<Constant>(Op0));
return true; return true;
} }

View File

@ -40,3 +40,18 @@ xx:
} }
declare noalias i8* @malloc(i64) nounwind declare noalias i8* @malloc(i64) nounwind
; PR8063
@permute_bitrev.bitrev = internal global i32* null, align 8
define void @permute_bitrev() nounwind {
entry:
%tmp = load i32** @permute_bitrev.bitrev, align 8
%conv = sext i32 0 to i64
%mul = mul i64 %conv, 4
%call = call i8* @malloc(i64 %mul)
%0 = bitcast i8* %call to i32*
store i32* %0, i32** @permute_bitrev.bitrev, align 8
ret void
}