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;