From 51c26e911af1b269234da336a03977153cf08d46 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 7 Mar 2006 01:28:57 +0000 Subject: [PATCH] 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 --- lib/Transforms/Scalar/InstructionCombining.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index a3eb9502539..3eb452c7901 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(V)) { + } else if (isa(V) || + (isa(V) && + cast(V)->getOpcode() == Instruction::Cast)) { + User *CI = cast(V); if (isa(CI->getOperand(0)->getType())) return GetKnownAlignment(CI->getOperand(0), TD); return 0; - } else if (GetElementPtrInst *GEPI = dyn_cast(V)) { + } else if (isa(V) || + (isa(V) && + cast(V)->getOpcode()==Instruction::GetElementPtr)) { + User *GEPI = cast(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(BasePtrTy)->getElementType()) - <= BaseAlignment) - return TD->getTypeAlignment(GEPI->getType()->getElementType()); + <= BaseAlignment) { + const Type *GEPTy = GEPI->getType(); + return TD->getTypeAlignment(cast(GEPTy)->getElementType()); + } return 0; } return 0;