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

Chris Lattner lattner at cs.uiuc.edu
Sat Jun 21 18:13:01 PDT 2003


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.90 -> 1.91

---
Log message:

Instcombine cast (getelementptr Ptr, 0, 0, 0) to ... into: cast Ptr to ...
This fixes type safety problems in a variety of benchmarks that were confusing
DSA.



---
Diffs of the changes:

Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.90 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.91
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.90	Thu Jun 19 12:00:31 2003
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Sat Jun 21 18:12:02 2003
@@ -930,6 +930,23 @@
     }
   }
 
+  // If casting the result of a getelementptr instruction with no offset, turn
+  // this into a cast of the original pointer!
+  //
+  if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(CI.getOperand(0))) {
+    bool AllZeroOperands = true;
+    for (unsigned i = 1, e = GEP->getNumOperands(); i != e; ++i)
+      if (!isa<Constant>(GEP->getOperand(i)) ||
+          !cast<Constant>(GEP->getOperand(i))->isNullValue()) {
+        AllZeroOperands = false;
+        break;
+      }
+    if (AllZeroOperands) {
+      CI.setOperand(0, GEP->getOperand(0));
+      return &CI;
+    }
+  }
+
   return 0;
 }
 





More information about the llvm-commits mailing list