Fix a bug with inttoptr/ptrtoint casts where the pointer has a different
authorDan Gohman <gohman@apple.com>
Thu, 16 Apr 2009 19:25:55 +0000 (19:25 +0000)
committerDan Gohman <gohman@apple.com>
Thu, 16 Apr 2009 19:25:55 +0000 (19:25 +0000)
size from the integer, requiring zero extension or truncation. Don't
create ZExtInsts with pointer types. This fixes a regression in
consumer-jpeg.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@69307 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ScalarEvolution.cpp
lib/Analysis/ScalarEvolutionExpander.cpp

index 972e4e984c63558f4b2deef887b6b9f41eb954e4..a3a6ff33332e0ded0e19d207c17b9f542e086263 100644 (file)
@@ -225,8 +225,6 @@ SCEVZeroExtendExpr::SCEVZeroExtendExpr(const SCEVHandle &op, const Type *ty)
   assert((Op->getType()->isInteger() || isa<PointerType>(Op->getType())) &&
          (Ty->isInteger() || isa<PointerType>(Ty)) &&
          "Cannot zero extend non-integer value!");
-  assert(Op->getType()->getPrimitiveSizeInBits() < Ty->getPrimitiveSizeInBits()
-         && "This is not an extending conversion!");
 }
 
 SCEVZeroExtendExpr::~SCEVZeroExtendExpr() {
@@ -674,7 +672,12 @@ SCEVHandle ScalarEvolution::getTruncateExpr(const SCEVHandle &Op, const Type *Ty
   return Result;
 }
 
-SCEVHandle ScalarEvolution::getZeroExtendExpr(const SCEVHandle &Op, const Type *Ty) {
+SCEVHandle ScalarEvolution::getZeroExtendExpr(const SCEVHandle &Op,
+                                              const Type *Ty) {
+  assert(getTargetData().getTypeSizeInBits(Op->getType()) <
+         getTargetData().getTypeSizeInBits(Ty) &&
+         "This is not an extending conversion!");
+
   if (SCEVConstant *SC = dyn_cast<SCEVConstant>(Op)) {
     const Type *IntTy = Ty;
     if (isa<PointerType>(IntTy)) IntTy = getTargetData().getIntPtrType();
index 6300f1ff113f756ca8729fc53ecc909bd79d0345..0e0eb55a0586933238dfd69eae06e9796fc24cf8 100644 (file)
@@ -281,17 +281,21 @@ Value *SCEVExpander::visitTruncateExpr(SCEVTruncateExpr *S) {
 }
 
 Value *SCEVExpander::visitZeroExtendExpr(SCEVZeroExtendExpr *S) {
+  const Type *Ty = S->getType();
+  if (isa<PointerType>(Ty)) Ty = TD.getIntPtrType();
   Value *V = expand(S->getOperand());
   if (isa<PointerType>(V->getType()))
     V = InsertCastOfTo(Instruction::PtrToInt, V, TD.getIntPtrType());
-  return CastInst::CreateZExtOrBitCast(V, S->getType(), "tmp.", InsertPt);
+  return CastInst::CreateZExtOrBitCast(V, Ty, "tmp.", InsertPt);
 }
 
 Value *SCEVExpander::visitSignExtendExpr(SCEVSignExtendExpr *S) {
+  const Type *Ty = S->getType();
+  if (isa<PointerType>(Ty)) Ty = TD.getIntPtrType();
   Value *V = expand(S->getOperand());
   if (isa<PointerType>(V->getType()))
     V = InsertCastOfTo(Instruction::PtrToInt, V, TD.getIntPtrType());
-  return CastInst::CreateSExtOrBitCast(V, S->getType(), "tmp.", InsertPt);
+  return CastInst::CreateSExtOrBitCast(V, Ty, "tmp.", InsertPt);
 }
 
 Value *SCEVExpander::visitSMaxExpr(SCEVSMaxExpr *S) {