Use type helper functions instead of cast

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188338 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Matt Arsenault 2013-08-14 00:24:34 +00:00
parent c2a484164d
commit 3ea117e1bc
2 changed files with 8 additions and 11 deletions

View File

@ -1379,8 +1379,7 @@ Instruction *InstCombiner::commonPointerCastTransforms(CastInst &CI) {
GEP->accumulateConstantOffset(*TD, Offset)) { GEP->accumulateConstantOffset(*TD, Offset)) {
// Get the base pointer input of the bitcast, and the type it points to. // Get the base pointer input of the bitcast, and the type it points to.
Value *OrigBase = cast<BitCastInst>(GEP->getOperand(0))->getOperand(0); Value *OrigBase = cast<BitCastInst>(GEP->getOperand(0))->getOperand(0);
Type *GEPIdxTy = Type *GEPIdxTy = OrigBase->getType()->getPointerElementType();
cast<PointerType>(OrigBase->getType())->getElementType();
SmallVector<Value*, 8> NewIndices; SmallVector<Value*, 8> NewIndices;
if (FindElementAtOffset(GEPIdxTy, Offset.getSExtValue(), NewIndices)) { if (FindElementAtOffset(GEPIdxTy, Offset.getSExtValue(), NewIndices)) {
// If we were able to index down into an element, create the GEP // If we were able to index down into an element, create the GEP
@ -1797,10 +1796,9 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) {
// Okay, we have (bitcast (shuffle ..)). Check to see if this is // Okay, we have (bitcast (shuffle ..)). Check to see if this is
// a bitcast to a vector with the same # elts. // a bitcast to a vector with the same # elts.
if (SVI->hasOneUse() && DestTy->isVectorTy() && if (SVI->hasOneUse() && DestTy->isVectorTy() &&
cast<VectorType>(DestTy)->getNumElements() == DestTy->getVectorNumElements() == SVI->getType()->getNumElements() &&
SVI->getType()->getNumElements() &&
SVI->getType()->getNumElements() == SVI->getType()->getNumElements() ==
cast<VectorType>(SVI->getOperand(0)->getType())->getNumElements()) { SVI->getOperand(0)->getType()->getVectorNumElements()) {
BitCastInst *Tmp; BitCastInst *Tmp;
// If either of the operands is a cast from CI.getType(), then // If either of the operands is a cast from CI.getType(), then
// evaluating the shuffle in the casted destination's type will allow // evaluating the shuffle in the casted destination's type will allow

View File

@ -1231,9 +1231,9 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
// %t = getelementptr i32* bitcast ([2 x i32]* %str to i32*), i32 %V // %t = getelementptr i32* bitcast ([2 x i32]* %str to i32*), i32 %V
// into: %t1 = getelementptr [2 x i32]* %str, i32 0, i32 %V; bitcast // into: %t1 = getelementptr [2 x i32]* %str, i32 0, i32 %V; bitcast
Type *SrcElTy = StrippedPtrTy->getElementType(); Type *SrcElTy = StrippedPtrTy->getElementType();
Type *ResElTy=cast<PointerType>(PtrOp->getType())->getElementType(); Type *ResElTy = PtrOp->getType()->getPointerElementType();
if (TD && SrcElTy->isArrayTy() && if (TD && SrcElTy->isArrayTy() &&
TD->getTypeAllocSize(cast<ArrayType>(SrcElTy)->getElementType()) == TD->getTypeAllocSize(SrcElTy->getArrayElementType()) ==
TD->getTypeAllocSize(ResElTy)) { TD->getTypeAllocSize(ResElTy)) {
Value *Idx[2]; Value *Idx[2];
Idx[0] = Constant::getNullValue(Type::getInt32Ty(GEP.getContext())); Idx[0] = Constant::getNullValue(Type::getInt32Ty(GEP.getContext()));
@ -1287,8 +1287,8 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
// Check that changing to the array element type amounts to dividing the // Check that changing to the array element type amounts to dividing the
// index by a scale factor. // index by a scale factor.
uint64_t ResSize = TD->getTypeAllocSize(ResElTy); uint64_t ResSize = TD->getTypeAllocSize(ResElTy);
uint64_t ArrayEltSize = uint64_t ArrayEltSize
TD->getTypeAllocSize(cast<ArrayType>(SrcElTy)->getElementType()); = TD->getTypeAllocSize(SrcElTy->getArrayElementType());
if (ResSize && ArrayEltSize % ResSize == 0) { if (ResSize && ArrayEltSize % ResSize == 0) {
Value *Idx = GEP.getOperand(1); Value *Idx = GEP.getOperand(1);
unsigned BitWidth = Idx->getType()->getPrimitiveSizeInBits(); unsigned BitWidth = Idx->getType()->getPrimitiveSizeInBits();
@ -1354,8 +1354,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
// field at Offset in 'A's type. If so, we can pull the cast through the // field at Offset in 'A's type. If so, we can pull the cast through the
// GEP. // GEP.
SmallVector<Value*, 8> NewIndices; SmallVector<Value*, 8> NewIndices;
Type *InTy = Type *InTy = BCI->getOperand(0)->getType()->getPointerElementType();
cast<PointerType>(BCI->getOperand(0)->getType())->getElementType();
if (FindElementAtOffset(InTy, Offset.getSExtValue(), NewIndices)) { if (FindElementAtOffset(InTy, Offset.getSExtValue(), NewIndices)) {
Value *NGEP = GEP.isInBounds() ? Value *NGEP = GEP.isInBounds() ?
Builder->CreateInBoundsGEP(BCI->getOperand(0), NewIndices) : Builder->CreateInBoundsGEP(BCI->getOperand(0), NewIndices) :