aboutsummaryrefslogtreecommitdiffstats
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
commit51c26e911af1b269234da336a03977153cf08d46 (patch)
tree1d8b5b0932756bea01bdcc0041f3474b76b43be3
parentb18966c28caea4d3e1a3263155521ddfa7091252 (diff)
downloadexternal_llvm-51c26e911af1b269234da336a03977153cf08d46.zip
external_llvm-51c26e911af1b269234da336a03977153cf08d46.tar.gz
external_llvm-51c26e911af1b269234da336a03977153cf08d46.tar.bz2
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
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index a3eb950..3eb452c 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/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;