[llvm-commits] [llvm] r61849 - /llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp

Chris Lattner sabre at nondot.org
Tue Jan 6 22:25:09 PST 2009


Author: lattner
Date: Wed Jan  7 00:25:07 2009
New Revision: 61849

URL: http://llvm.org/viewvc/llvm-project?rev=61849&view=rev
Log:
Use the hasAllZeroIndices predicate to simplify some 
code, no functionality change.

Modified:
    llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp?rev=61849&r1=61848&r2=61849&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/ScalarReplAggregates.cpp Wed Jan  7 00:25:07 2009
@@ -377,23 +377,8 @@
     }
     
     // If this GEP is to the start of the aggregate, check for memcpys.
-    if (Idx == 0) {
-      bool IsStartOfAggregateGEP = true;
-      for (unsigned i = 3, e = GEPI->getNumOperands(); i != e; ++i) {
-        if (!isa<ConstantInt>(GEPI->getOperand(i))) {
-          IsStartOfAggregateGEP = false;
-          break;
-        }
-        if (!cast<ConstantInt>(GEPI->getOperand(i))->isZero()) {
-          IsStartOfAggregateGEP = false;
-          break;
-        }
-      }
-      
-      if (IsStartOfAggregateGEP)
-        RewriteBitCastUserOfAlloca(GEPI, AI, ElementAllocas);
-    }
-    
+    if (Idx == 0 && GEPI->hasAllZeroIndices())
+      RewriteBitCastUserOfAlloca(GEPI, AI, ElementAllocas);
 
     // Move all of the users over to the new GEP.
     GEPI->replaceAllUsesWith(RepValue);
@@ -431,15 +416,8 @@
           // Using pointer arithmetic to navigate the array.
           return MarkUnsafe(Info);
        
-        if (AreAllZeroIndices) {
-          for (unsigned i = 2, e = GEP->getNumOperands(); i != e; ++i) {
-            if (!isa<ConstantInt>(GEP->getOperand(i)) ||    
-                !cast<ConstantInt>(GEP->getOperand(i))->isZero()) {
-              AreAllZeroIndices = false;
-              break;
-            }
-          }
-        }
+        if (AreAllZeroIndices)
+          AreAllZeroIndices = GEP->hasAllZeroIndices();
       }
       isSafeElementUse(GEP, AreAllZeroIndices, AI, Info);
       if (Info.isUnsafe) return;
@@ -662,7 +640,7 @@
       // It is likely that OtherPtr is a bitcast, if so, remove it.
       if (BitCastInst *BC = dyn_cast<BitCastInst>(OtherPtr))
         OtherPtr = BC->getOperand(0);
-      // All zero GEPs are effectively casts
+      // All zero GEPs are effectively bitcasts.
       if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(OtherPtr))
         if (GEP->hasAllZeroIndices())
           OtherPtr = GEP->getOperand(0);
@@ -1062,7 +1040,7 @@
                  isa<ConstantInt>(GEP->getOperand(2)) &&
                  cast<ConstantInt>(GEP->getOperand(1))->isZero()) {
         // We are stepping into an element, e.g. a structure or an array:
-        // GEP Ptr, int 0, uint C
+        // GEP Ptr, i32 0, i32 Cst
         const Type *AggTy = PTy->getElementType();
         unsigned Idx = cast<ConstantInt>(GEP->getOperand(2))->getZExtValue();
         





More information about the llvm-commits mailing list