From d900c6a8b3de655bac138cfdf4b9a85b7e64ec1c Mon Sep 17 00:00:00 2001 From: Robert Bocchino Date: Thu, 19 Jan 2006 23:53:23 +0000 Subject: [PATCH] ConstantFoldLoadThroughGEPConstantExpr wasn't handling pointers to packed types correctly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25470 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/Local.cpp | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp index f2598c16ce4..9685e94cc19 100644 --- a/lib/Transforms/Utils/Local.cpp +++ b/lib/Transforms/Utils/Local.cpp @@ -267,16 +267,29 @@ Constant *llvm::ConstantFoldLoadThroughGEPConstantExpr(Constant *C, return 0; } } else if (ConstantInt *CI = dyn_cast(I.getOperand())) { - const ArrayType *ATy = cast(*I); - if ((uint64_t)CI->getRawValue() >= ATy->getNumElements()) return 0; - if (ConstantArray *CA = dyn_cast(C)) - C = CA->getOperand((unsigned)CI->getRawValue()); - else if (isa(C)) - C = Constant::getNullValue(ATy->getElementType()); - else if (isa(C)) - C = UndefValue::get(ATy->getElementType()); - else + if (const ArrayType *ATy = dyn_cast(*I)) { + if ((uint64_t)CI->getRawValue() >= ATy->getNumElements()) return 0; + if (ConstantArray *CA = dyn_cast(C)) + C = CA->getOperand((unsigned)CI->getRawValue()); + else if (isa(C)) + C = Constant::getNullValue(ATy->getElementType()); + else if (isa(C)) + C = UndefValue::get(ATy->getElementType()); + else + return 0; + } else if (const PackedType *PTy = dyn_cast(*I)) { + if ((uint64_t)CI->getRawValue() >= PTy->getNumElements()) return 0; + if (ConstantPacked *CP = dyn_cast(C)) + C = CP->getOperand((unsigned)CI->getRawValue()); + else if (isa(C)) + C = Constant::getNullValue(PTy->getElementType()); + else if (isa(C)) + C = UndefValue::get(PTy->getElementType()); + else + return 0; + } else { return 0; + } } else { return 0; } -- 2.34.1