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

Chris Lattner lattner at cs.uiuc.edu
Mon Apr 25 13:17:43 PDT 2005



Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.329 -> 1.330
---
Log message:

implement getelementptr.ll:test10


---
Diffs of the changes:  (+19 -1)

 InstructionCombining.cpp |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletion(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.329 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.330
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.329	Sun Apr 24 12:46:05 2005
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Mon Apr 25 15:17:30 2005
@@ -2277,8 +2277,26 @@
                              Constant::getNullValue(Offset->getType()));
     }
   } else if (User *GEPRHS = dyn_castGetElementPtr(RHS)) {
-    if (PtrBase != GEPRHS->getOperand(0))
+    // If the base pointers are different, but the indices are the same, just
+    // compare the base pointer.
+    if (PtrBase != GEPRHS->getOperand(0)) {
+      bool IndicesTheSame = GEPLHS->getNumOperands()==GEPRHS->getNumOperands();
+      if (IndicesTheSame)
+        for (unsigned i = 1, e = GEPLHS->getNumOperands(); i != e; ++i)
+          if (GEPLHS->getOperand(i) != GEPRHS->getOperand(i)) {
+            IndicesTheSame = false;
+            break;
+          }
+
+      // If all indices are the same, just compare the base pointers.
+      if (IndicesTheSame)
+        return new SetCondInst(Cond, GEPLHS->getOperand(0),
+                               GEPRHS->getOperand(0));
+
+      // Otherwise, the base pointers are different and the indices are
+      // different, bail out.
       return 0;
+    }
 
     // If one of the GEPs has all zero indices, recurse.
     bool AllZeros = true;






More information about the llvm-commits mailing list