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

Chris Lattner lattner at cs.uiuc.edu
Sat Dec 6 19:25:01 PST 2003


Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.143 -> 1.144

---
Log message:

* Finegrainify namespacification
* Transform: free <ty>* (cast <ty2>* X to <ty>*) into free <ty2>* X



---
Diffs of the changes:  (+17 -4)

Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.143 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.144
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.143	Thu Nov 13 13:17:02 2003
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Sat Dec  6 19:24:23 2003
@@ -48,8 +48,7 @@
 #include "llvm/Support/CallSite.h"
 #include "Support/Statistic.h"
 #include <algorithm>
-
-namespace llvm {
+using namespace llvm;
 
 namespace {
   Statistic<> NumCombined ("instcombine", "Number of insts combined");
@@ -104,6 +103,7 @@
     Instruction *visitPHINode(PHINode &PN);
     Instruction *visitGetElementPtrInst(GetElementPtrInst &GEP);
     Instruction *visitAllocationInst(AllocationInst &AI);
+    Instruction *visitFreeInst(FreeInst &FI);
     Instruction *visitLoadInst(LoadInst &LI);
     Instruction *visitBranchInst(BranchInst &BI);
 
@@ -2044,6 +2044,20 @@
   return 0;
 }
 
+Instruction *InstCombiner::visitFreeInst(FreeInst &FI) {
+  Value *Op = FI.getOperand(0);
+
+  // Change free <ty>* (cast <ty2>* X to <ty>*) into free <ty2>* X
+  if (CastInst *CI = dyn_cast<CastInst>(Op))
+    if (isa<PointerType>(CI->getOperand(0)->getType())) {
+      FI.setOperand(0, CI->getOperand(0));
+      return &FI;
+    }
+
+  return 0;
+}
+
+
 /// GetGEPGlobalInitializer - Given a constant, and a getelementptr
 /// constantexpr, return the constant value being addressed by the constant
 /// expression, or null if something is funny.
@@ -2196,8 +2210,7 @@
   return Changed;
 }
 
-Pass *createInstructionCombiningPass() {
+Pass *llvm::createInstructionCombiningPass() {
   return new InstCombiner();
 }
 
-} // End llvm namespace





More information about the llvm-commits mailing list