[llvm-commits] [llvm] r69293 - in /llvm/trunk: include/llvm/Analysis/ScalarEvolutionExpander.h lib/Analysis/ScalarEvolutionExpander.cpp

Dan Gohman gohman at apple.com
Thu Apr 16 08:52:57 PDT 2009


Author: djg
Date: Thu Apr 16 10:52:57 2009
New Revision: 69293

URL: http://llvm.org/viewvc/llvm-project?rev=69293&view=rev
Log:
Teach SCEVExpander::InsertCastOfTo to avoid creating inttoptr-of-ptrtoint
and ptrtoint-of-inttoptr expressions. This fixes a regression in 300.twolf.

Modified:
    llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpander.h
    llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp

Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpander.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpander.h?rev=69293&r1=69292&r2=69293&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpander.h (original)
+++ llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpander.h Thu Apr 16 10:52:57 2009
@@ -83,8 +83,8 @@
 
     /// InsertCastOfTo - Insert a cast of V to the specified type, doing what
     /// we can to share the casts.
-    static Value *InsertCastOfTo(Instruction::CastOps opcode, Value *V, 
-                                 const Type *Ty);
+    Value *InsertCastOfTo(Instruction::CastOps opcode, Value *V,
+                          const Type *Ty);
     /// InsertBinop - Insert the specified binary operator, doing a small amount
     /// of work to avoid inserting an obviously redundant operation.
     static Value *InsertBinop(Instruction::BinaryOps Opcode, Value *LHS,

Modified: llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp?rev=69293&r1=69292&r2=69293&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp Thu Apr 16 10:52:57 2009
@@ -26,6 +26,14 @@
   if (opcode == Instruction::BitCast && V->getType() == Ty)
     return V;
 
+  // Short-circuit unnecessary inttoptr<->ptrtoint casts.
+  if (opcode == Instruction::PtrToInt && Ty == TD.getIntPtrType())
+    if (IntToPtrInst *ITP = dyn_cast<IntToPtrInst>(V))
+      return ITP->getOperand(0);
+  if (opcode == Instruction::IntToPtr && V->getType() == TD.getIntPtrType())
+    if (PtrToIntInst *PTI = dyn_cast<PtrToIntInst>(V))
+      return PTI->getOperand(0);
+
   // FIXME: keep track of the cast instruction.
   if (Constant *C = dyn_cast<Constant>(V))
     return ConstantExpr::getCast(opcode, C, Ty);





More information about the llvm-commits mailing list