[llvm-commits] [llvm] r70553 - /llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp

Dan Gohman gohman at apple.com
Fri May 1 10:00:01 PDT 2009


Author: djg
Date: Fri May  1 12:00:00 2009
New Revision: 70553

URL: http://llvm.org/viewvc/llvm-project?rev=70553&view=rev
Log:
Short-circuit inttoptr-ptrtoint constant expressions; these aren't
always folded by the regular constant folder because it doesn't have
TargetData information.

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

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

==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp Fri May  1 12:00:00 2009
@@ -27,13 +27,20 @@
 
   // Short-circuit unnecessary inttoptr<->ptrtoint casts.
   if ((opcode == Instruction::PtrToInt || opcode == Instruction::IntToPtr) &&
-      SE.getTypeSizeInBits(Ty) == SE.getTypeSizeInBits(V->getType()))
+      SE.getTypeSizeInBits(Ty) == SE.getTypeSizeInBits(V->getType())) {
     if (CastInst *CI = dyn_cast<CastInst>(V))
       if ((CI->getOpcode() == Instruction::PtrToInt ||
            CI->getOpcode() == Instruction::IntToPtr) &&
           SE.getTypeSizeInBits(CI->getType()) ==
           SE.getTypeSizeInBits(CI->getOperand(0)->getType()))
         return CI->getOperand(0);
+    if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
+      if ((CE->getOpcode() == Instruction::PtrToInt ||
+           CE->getOpcode() == Instruction::IntToPtr) &&
+          SE.getTypeSizeInBits(CE->getType()) ==
+          SE.getTypeSizeInBits(CE->getOperand(0)->getType()))
+        return CE->getOperand(0);
+  }
 
   // FIXME: keep track of the cast instruction.
   if (Constant *C = dyn_cast<Constant>(V))





More information about the llvm-commits mailing list