From: Matt Arsenault Date: Mon, 19 Aug 2013 22:17:18 +0000 (+0000) Subject: commonPointerCast cleanups to make address space change easier X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=5c40cc2e1e560ab8ba1b79fc5cf5a302643b2f4c;p=oota-llvm.git commonPointerCast cleanups to make address space change easier git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188719 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/InstCombine/InstCombineCasts.cpp b/lib/Transforms/InstCombine/InstCombineCasts.cpp index d31f84511eb..bad37568fdf 100644 --- a/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -1370,15 +1370,21 @@ Instruction *InstCombiner::commonPointerCastTransforms(CastInst &CI) { return &CI; } + if (!TD) + return commonCastTransforms(CI); + // If the GEP has a single use, and the base pointer is a bitcast, and the // GEP computes a constant offset, see if we can convert these three // instructions into fewer. This typically happens with unions and other // non-type-safe code. - APInt Offset(TD ? TD->getPointerSizeInBits() : 1, 0); - if (TD && GEP->hasOneUse() && isa(GEP->getOperand(0)) && + unsigned OffsetBits = TD->getPointerSizeInBits(); + APInt Offset(OffsetBits, 0); + BitCastInst *BCI = dyn_cast(GEP->getOperand(0)); + if (GEP->hasOneUse() && + BCI && GEP->accumulateConstantOffset(*TD, Offset)) { // Get the base pointer input of the bitcast, and the type it points to. - Value *OrigBase = cast(GEP->getOperand(0))->getOperand(0); + Value *OrigBase = BCI->getOperand(0); Type *GEPIdxTy = OrigBase->getType()->getPointerElementType(); SmallVector NewIndices; if (FindElementAtOffset(GEPIdxTy, Offset.getSExtValue(), NewIndices)) { @@ -1386,8 +1392,8 @@ Instruction *InstCombiner::commonPointerCastTransforms(CastInst &CI) { // and bitcast the result. This eliminates one bitcast, potentially // two. Value *NGEP = cast(GEP)->isInBounds() ? - Builder->CreateInBoundsGEP(OrigBase, NewIndices) : - Builder->CreateGEP(OrigBase, NewIndices); + Builder->CreateInBoundsGEP(OrigBase, NewIndices) : + Builder->CreateGEP(OrigBase, NewIndices); NGEP->takeName(GEP); if (isa(CI))