[llvm] r194221 - IR: Properly canonicalize PointerType in ConstantExpr GEPs

David Majnemer david.majnemer at gmail.com
Thu Nov 7 14:29:42 PST 2013


Author: majnemer
Date: Thu Nov  7 16:29:42 2013
New Revision: 194221

URL: http://llvm.org/viewvc/llvm-project?rev=194221&view=rev
Log:
IR: Properly canonicalize PointerType in ConstantExpr GEPs

No additional test was needed, Other/constant-fold-gep.ll detects this
just fine.

Modified:
    llvm/trunk/lib/IR/ConstantFold.cpp

Modified: llvm/trunk/lib/IR/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/ConstantFold.cpp?rev=194221&r1=194220&r2=194221&view=diff
==============================================================================
--- llvm/trunk/lib/IR/ConstantFold.cpp (original)
+++ llvm/trunk/lib/IR/ConstantFold.cpp Thu Nov  7 16:29:42 2013
@@ -1966,11 +1966,12 @@ static Constant *ConstantFoldGetElementP
         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())





More information about the llvm-commits mailing list