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

Andrew Lenharth alenhar2 at cs.uiuc.edu
Tue Sep 19 11:25:09 PDT 2006



Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.510 -> 1.511
---
Log message:

If we have an add, do it in the pointer realm, not the int realm.  This is critical in the linux kernel for pointer analysis correctness

---
Diffs of the changes:  (+22 -0)

 InstructionCombining.cpp |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.510 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.511
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.510	Tue Sep 19 01:18:21 2006
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Tue Sep 19 13:24:51 2006
@@ -1595,6 +1595,28 @@
         return R;
   }
 
+  // add (cast *A to intptrtype) B -> cast (GEP (cast *A to sbyte*) B) -> intptrtype
+  {
+    CastInst* CI = dyn_cast<CastInst>(LHS);
+    Value* Other = RHS;
+    if (!CI) {
+      CI = dyn_cast<CastInst>(RHS);
+      Other = LHS;
+    }
+    if (CI) {
+      const Type *UIntPtrTy = TD->getIntPtrType();
+      const Type *SIntPtrTy = UIntPtrTy->getSignedVersion();
+      if((CI->getType() == UIntPtrTy || CI->getType() == SIntPtrTy) 
+	 && isa<PointerType>(CI->getOperand(0)->getType())) {
+	Instruction* I2 = new CastInst(CI->getOperand(0), PointerType::get(Type::SByteTy), "ctg", &I);
+	WorkList.push_back(I2);
+	I2 = new GetElementPtrInst(I2, Other, "ctg", &I);
+	WorkList.push_back(I2);
+	return new CastInst(I2, CI->getType());
+      }
+    }
+  }
+
   return Changed ? &I : 0;
 }
 






More information about the llvm-commits mailing list