Teach the alignment handling code to look through constant expr casts and GEPs

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26580 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2006-03-07 01:28:57 +00:00
parent b18966c28c
commit 51c26e911a

View File

@ -5285,11 +5285,17 @@ static unsigned GetKnownAlignment(Value *V, TargetData *TD) {
}
}
return Align;
} else if (CastInst *CI = dyn_cast<CastInst>(V)) {
} else if (isa<CastInst>(V) ||
(isa<ConstantExpr>(V) &&
cast<ConstantExpr>(V)->getOpcode() == Instruction::Cast)) {
User *CI = cast<User>(V);
if (isa<PointerType>(CI->getOperand(0)->getType()))
return GetKnownAlignment(CI->getOperand(0), TD);
return 0;
} else if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(V)) {
} else if (isa<GetElementPtrInst>(V) ||
(isa<ConstantExpr>(V) &&
cast<ConstantExpr>(V)->getOpcode()==Instruction::GetElementPtr)) {
User *GEPI = cast<User>(V);
unsigned BaseAlignment = GetKnownAlignment(GEPI->getOperand(0), TD);
if (BaseAlignment == 0) return 0;
@ -5311,8 +5317,10 @@ static unsigned GetKnownAlignment(Value *V, TargetData *TD) {
const Type *BasePtrTy = GEPI->getOperand(0)->getType();
if (TD->getTypeAlignment(cast<PointerType>(BasePtrTy)->getElementType())
<= BaseAlignment)
return TD->getTypeAlignment(GEPI->getType()->getElementType());
<= BaseAlignment) {
const Type *GEPTy = GEPI->getType();
return TD->getTypeAlignment(cast<PointerType>(GEPTy)->getElementType());
}
return 0;
}
return 0;