From 921ef3a1857c60d1ec7530b6cefe5b277d3e7c33 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 7 Mar 2002 21:17:35 +0000 Subject: [PATCH] Support changing the pointer type of a store for the case where we are storing into the first element of the structure type. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1832 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/ExprTypeConvert.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/Transforms/ExprTypeConvert.cpp b/lib/Transforms/ExprTypeConvert.cpp index d716bca76de..cbf22b035a8 100644 --- a/lib/Transforms/ExprTypeConvert.cpp +++ b/lib/Transforms/ExprTypeConvert.cpp @@ -721,6 +721,18 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty, const Type *ElTy = PT->getElementType(); assert(V == I->getOperand(1)); + if (isa(ElTy)) { + // We can change the destination pointer if we can store our first + // argument into the first element of the structure... + // + unsigned Offset = 0; + std::vector Indices; + ElTy = getStructOffsetType(ElTy, Offset, Indices, false); + assert(Offset == 0 && "Offset changed!"); + if (ElTy == 0) // Element at offset zero in struct doesn't exist! + return false; // Can only happen for {}* + } + // Must move the same amount of data... if (TD.getTypeSize(ElTy) != TD.getTypeSize(I->getOperand(0)->getType())) return false; @@ -959,13 +971,14 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal, } else { // Replace the source pointer const Type *ValTy = cast(NewTy)->getElementType(); std::vector Indices; -#if 0 - Indices.push_back(ConstantUInt::get(Type::UIntTy, 0)); - while (ArrayType *AT = dyn_cast(ValTy)) { + + if (isa(ValTy)) { + unsigned Offset = 0; Indices.push_back(ConstantUInt::get(Type::UIntTy, 0)); - ValTy = AT->getElementType(); + ValTy = getStructOffsetType(ValTy, Offset, Indices, false); + assert(Offset == 0 && ValTy); } -#endif + Res = new StoreInst(Constant::getNullConstant(ValTy), NewVal, Indices); VMC.ExprMap[I] = Res; Res->setOperand(0, ConvertExpressionToType(I->getOperand(0), ValTy, VMC));