IR: Properly canonicalize PointerType in ConstantExpr GEPs
authorDavid Majnemer <david.majnemer@gmail.com>
Thu, 7 Nov 2013 22:29:42 +0000 (22:29 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Thu, 7 Nov 2013 22:29:42 +0000 (22:29 +0000)
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

lib/IR/ConstantFold.cpp

index 46e391abb04d7f2fefc3d89cca775d16261e611a..3219be11b682d09a330ff458faef4d7ac972844c 100644 (file)
@@ -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())