aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2013-11-07 22:29:42 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2013-11-07 22:29:42 +0000
commitf9c692cfeb9a73bad531f86d9f103e67d3d0e162 (patch)
tree772d60011a4709ee0b7afe3dfecc5811d9d86ac5 /lib
parent0ab20588523b59a65a4a29d47184a41443fa9337 (diff)
downloadexternal_llvm-f9c692cfeb9a73bad531f86d9f103e67d3d0e162.zip
external_llvm-f9c692cfeb9a73bad531f86d9f103e67d3d0e162.tar.gz
external_llvm-f9c692cfeb9a73bad531f86d9f103e67d3d0e162.tar.bz2
IR: Properly canonicalize PointerType in ConstantExpr GEPs
No additional test was needed, Other/constant-fold-gep.ll detects this just fine. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194221 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/IR/ConstantFold.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/IR/ConstantFold.cpp b/lib/IR/ConstantFold.cpp
index 46e391a..3219be1 100644
--- a/lib/IR/ConstantFold.cpp
+++ b/lib/IR/ConstantFold.cpp
@@ -1966,11 +1966,12 @@ static Constant *ConstantFoldGetElementPtrImpl(Constant *C,
else if (VectorType *VTy = dyn_cast<VectorType>(LastTy))
NumElements = VTy->getNumElements();
- if (ConstantInt *CI = dyn_cast<ConstantInt>(Idx0)) {
- int64_t Idx0Val = CI->getSExtValue();
- if (NumElements > 0 && Idx0Val >= 0 &&
- (uint64_t)Idx0Val < NumElements)
- IsSequentialAccessInRange = true;
+ if (NumElements > 0) {
+ if (ConstantInt *CI = dyn_cast<ConstantInt>(Idx0)) {
+ int64_t Idx0Val = CI->getSExtValue();
+ if (Idx0Val >= 0 && (uint64_t)Idx0Val < NumElements)
+ IsSequentialAccessInRange = true;
+ }
} else if (PointerType *PTy = dyn_cast<PointerType>(LastTy))
// Only handle pointers to sized types, not pointers to functions.
if (PTy->getElementType()->isSized())