[llvm-commits] CVS: llvm/lib/Transforms/Scalar/DecomposeMultiDimRefs.cpp

Brian Gaeke gaeke at cs.uiuc.edu
Tue Jul 6 13:16:01 PDT 2004


Changes in directory llvm/lib/Transforms/Scalar:

DecomposeMultiDimRefs.cpp updated: 1.32 -> 1.33

---
Log message:

Add helper function.
Don't touch GEPs for which DecomposeArrayRef is not going to do anything
special (e.g., < 2 indices, or 2 indices and the last one is a constant.)


---
Diffs of the changes:  (+14 -2)

Index: llvm/lib/Transforms/Scalar/DecomposeMultiDimRefs.cpp
diff -u llvm/lib/Transforms/Scalar/DecomposeMultiDimRefs.cpp:1.32 llvm/lib/Transforms/Scalar/DecomposeMultiDimRefs.cpp:1.33
--- llvm/lib/Transforms/Scalar/DecomposeMultiDimRefs.cpp:1.32	Fri Jul  2 00:30:01 2004
+++ llvm/lib/Transforms/Scalar/DecomposeMultiDimRefs.cpp	Tue Jul  6 13:15:39 2004
@@ -24,6 +24,7 @@
 #include "llvm/BasicBlock.h"
 #include "llvm/Pass.h"
 #include "Support/Statistic.h"
+#include "Support/Debug.h"
 using namespace llvm;
 
 namespace {
@@ -52,6 +53,10 @@
   return new DecomposePass();
 }
 
+static inline bool isZeroConst (Value *V) {
+  return isa<Constant> (V) && (cast<Constant>(V)->isNullValue());
+}
+
 // Function: DecomposeArrayRef()
 //  
 // For any GetElementPtrInst with 2 or more array and structure indices:
@@ -76,8 +81,15 @@
 // Return value: true if the instruction was replaced; false otherwise.
 // 
 bool llvm::DecomposeArrayRef(GetElementPtrInst* GEP) {
-  if (GEP->getNumIndices() < 2)
+  if (GEP->getNumIndices() < 2
+      || (GEP->getNumIndices() == 2
+          && isZeroConst(GEP->getOperand(1))
+          && isa<ConstantInt>(GEP->getOperand(2)))) {
+    DEBUG (std::cerr << "DecomposeArrayRef: Skipping " << *GEP);
     return false;
+  } else {
+    DEBUG (std::cerr << "DecomposeArrayRef: Decomposing " << *GEP);
+  }
 
   BasicBlock *BB = GEP->getParent();
   Value *LastPtr = GEP->getPointerOperand();
@@ -90,7 +102,7 @@
     
     // If this is the first index and is 0, skip it and move on!
     if (OI == GEP->idx_begin()) {
-      if (*OI == ConstantInt::getNullValue((*OI)->getType()))
+      if (isZeroConst (*OI))
         continue;
     }
     else // Not the first index: include initial [0] to deref the last ptr





More information about the llvm-commits mailing list