summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-03-07 01:28:57 +0000
committerChris Lattner <sabre@nondot.org>2006-03-07 01:28:57 +0000
commit53ef5a032cdfb6cf3fc3b24abfc6a71d8ee57229 (patch)
tree200ea1dea8d6fbd3438bffcaa5b84772baddeecf /llvm/lib/Transforms/Scalar/InstructionCombining.cpp
parent9b4ebee87158107109a5529fee4270bd4edc52aa (diff)
downloadbcm5719-llvm-53ef5a032cdfb6cf3fc3b24abfc6a71d8ee57229.tar.gz
bcm5719-llvm-53ef5a032cdfb6cf3fc3b24abfc6a71d8ee57229.zip
Teach the alignment handling code to look through constant expr casts and GEPs
llvm-svn: 26580
Diffstat (limited to 'llvm/lib/Transforms/Scalar/InstructionCombining.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index a3eb9502539..3eb452c7901 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -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;
OpenPOWER on IntegriCloud