Various code simplifications.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95044 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman
2010-02-02 01:38:49 +00:00
parent 87641fa6dc
commit 8db08df5d3

View File

@ -351,17 +351,15 @@ bool SCEVUnknown::isSizeOf(const Type *&AllocTy) const {
if (ConstantExpr *VCE = dyn_cast<ConstantExpr>(V)) if (ConstantExpr *VCE = dyn_cast<ConstantExpr>(V))
if (VCE->getOpcode() == Instruction::PtrToInt) if (VCE->getOpcode() == Instruction::PtrToInt)
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(VCE->getOperand(0))) if (ConstantExpr *CE = dyn_cast<ConstantExpr>(VCE->getOperand(0)))
if (CE->getOpcode() == Instruction::GetElementPtr) if (CE->getOpcode() == Instruction::GetElementPtr &&
if (CE->getOperand(0)->isNullValue()) { CE->getOperand(0)->isNullValue() &&
const Type *Ty = CE->getNumOperands() == 2)
cast<PointerType>(CE->getOperand(0)->getType())->getElementType(); if (ConstantInt *CI = dyn_cast<ConstantInt>(CE->getOperand(1)))
if (CE->getNumOperands() == 2) if (CI->isOne()) {
if (ConstantInt *CI = dyn_cast<ConstantInt>(CE->getOperand(1))) AllocTy = cast<PointerType>(CE->getOperand(0)->getType())
if (CI->isOne()) { ->getElementType();
AllocTy = Ty; return true;
return true; }
}
}
return false; return false;
} }
@ -370,23 +368,23 @@ bool SCEVUnknown::isAlignOf(const Type *&AllocTy) const {
if (ConstantExpr *VCE = dyn_cast<ConstantExpr>(V)) if (ConstantExpr *VCE = dyn_cast<ConstantExpr>(V))
if (VCE->getOpcode() == Instruction::PtrToInt) if (VCE->getOpcode() == Instruction::PtrToInt)
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(VCE->getOperand(0))) if (ConstantExpr *CE = dyn_cast<ConstantExpr>(VCE->getOperand(0)))
if (CE->getOpcode() == Instruction::GetElementPtr) if (CE->getOpcode() == Instruction::GetElementPtr &&
if (CE->getOperand(0)->isNullValue()) { CE->getOperand(0)->isNullValue()) {
const Type *Ty = const Type *Ty =
cast<PointerType>(CE->getOperand(0)->getType())->getElementType(); cast<PointerType>(CE->getOperand(0)->getType())->getElementType();
if (const StructType *STy = dyn_cast<StructType>(Ty)) if (const StructType *STy = dyn_cast<StructType>(Ty))
if (!STy->isPacked() && if (!STy->isPacked() &&
CE->getNumOperands() == 3 && CE->getNumOperands() == 3 &&
CE->getOperand(1)->isNullValue()) { CE->getOperand(1)->isNullValue()) {
if (ConstantInt *CI = dyn_cast<ConstantInt>(CE->getOperand(2))) if (ConstantInt *CI = dyn_cast<ConstantInt>(CE->getOperand(2)))
if (CI->isOne() && if (CI->isOne() &&
STy->getNumElements() == 2 && STy->getNumElements() == 2 &&
STy->getElementType(0)->isInteger(1)) { STy->getElementType(0)->isInteger(1)) {
AllocTy = STy->getElementType(1); AllocTy = STy->getElementType(1);
return true; return true;
} }
} }
} }
return false; return false;
} }
@ -2720,9 +2718,8 @@ const SCEV *ScalarEvolution::createNodeForGEP(GEPOperator *GEP) {
} else { } else {
// For an array, add the element offset, explicitly scaled. // For an array, add the element offset, explicitly scaled.
const SCEV *LocalOffset = getSCEV(Index); const SCEV *LocalOffset = getSCEV(Index);
if (!isa<PointerType>(LocalOffset->getType())) // Getelementptr indicies are signed.
// Getelementptr indicies are signed. LocalOffset = getTruncateOrSignExtend(LocalOffset, IntPtrTy);
LocalOffset = getTruncateOrSignExtend(LocalOffset, IntPtrTy);
// Lower "inbounds" GEPs to NSW arithmetic. // Lower "inbounds" GEPs to NSW arithmetic.
LocalOffset = getMulExpr(LocalOffset, getSizeOfExpr(*GTI), LocalOffset = getMulExpr(LocalOffset, getSizeOfExpr(*GTI),
/*HasNUW=*/false, /*HasNSW=*/InBounds); /*HasNUW=*/false, /*HasNSW=*/InBounds);