diff options
author | Chris Lattner <sabre@nondot.org> | 2010-08-26 22:14:59 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-08-26 22:14:59 +0000 |
commit | 26dbe7ec18740f642febcc738e628d921aafd079 (patch) | |
tree | 01e0d07d848ca5b8c7b637910d4abc981669e3ab /lib/Transforms/InstCombine/InstCombineCasts.cpp | |
parent | 1ab3f16f06698596716593a30545799688acccd7 (diff) |
optimize "integer extraction out of the middle of a vector" as produced
by SRoA. This is part of rdar://7892780, but needs another xform to
expose this.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112232 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/InstCombine/InstCombineCasts.cpp')
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineCasts.cpp | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineCasts.cpp b/lib/Transforms/InstCombine/InstCombineCasts.cpp index ef5bbc4798..82c359194f 100644 --- a/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -1337,31 +1337,53 @@ static Instruction *OptimizeVectorResize(Value *InVal, const VectorType *DestTy, /// OptimizeIntToFloatBitCast - See if we can optimize an integer->float/double /// bitcast. The various long double bitcasts can't get in here. -static Instruction *OptimizeIntToFloatBitCast(BitCastInst &CI,InstCombiner &IC) { +static Instruction *OptimizeIntToFloatBitCast(BitCastInst &CI,InstCombiner &IC){ Value *Src = CI.getOperand(0); + const Type *DestTy = CI.getType(); // If this is a bitcast from int to float, check to see if the int is an // extraction from a vector. Value *VecInput = 0; + // bitcast(trunc(bitcast(somevector))) if (match(Src, m_Trunc(m_BitCast(m_Value(VecInput)))) && isa<VectorType>(VecInput->getType())) { const VectorType *VecTy = cast<VectorType>(VecInput->getType()); - const Type *DestTy = CI.getType(); - - // If the element type of the vector doesn't match the result type, but the - // vector type's size is a multiple of the result type, bitcast it to be a - // vector type we can extract from. - if (VecTy->getElementType() != DestTy && - VecTy->getPrimitiveSizeInBits() % DestTy->getPrimitiveSizeInBits()==0) { - VecTy = VectorType::get(DestTy, - VecTy->getPrimitiveSizeInBits() / DestTy->getPrimitiveSizeInBits()); - VecInput = IC.Builder->CreateBitCast(VecInput, VecTy); - } + unsigned DestWidth = DestTy->getPrimitiveSizeInBits(); + + if (VecTy->getPrimitiveSizeInBits() % DestWidth == 0) { + // If the element type of the vector doesn't match the result type, + // bitcast it to be a vector type we can extract from. + if (VecTy->getElementType() != DestTy) { + VecTy = VectorType::get(DestTy, + VecTy->getPrimitiveSizeInBits() / DestWidth); + VecInput = IC.Builder->CreateBitCast(VecInput, VecTy); + } - if (VecTy->getElementType() == DestTy) return ExtractElementInst::Create(VecInput, IC.Builder->getInt32(0)); + } } + // bitcast(trunc(lshr(bitcast(somevector), cst)) + ConstantInt *ShAmt = 0; + if (match(Src, m_Trunc(m_LShr(m_BitCast(m_Value(VecInput)), + m_ConstantInt(ShAmt)))) && + isa<VectorType>(VecInput->getType())) { + const VectorType *VecTy = cast<VectorType>(VecInput->getType()); + unsigned DestWidth = DestTy->getPrimitiveSizeInBits(); + if (VecTy->getPrimitiveSizeInBits() % DestWidth == 0 && + ShAmt->getZExtValue() % DestWidth == 0) { + // If the element type of the vector doesn't match the result type, + // bitcast it to be a vector type we can extract from. + if (VecTy->getElementType() != DestTy) { + VecTy = VectorType::get(DestTy, + VecTy->getPrimitiveSizeInBits() / DestWidth); + VecInput = IC.Builder->CreateBitCast(VecInput, VecTy); + } + + unsigned Elt = ShAmt->getZExtValue() / DestWidth; + return ExtractElementInst::Create(VecInput, IC.Builder->getInt32(Elt)); + } + } return 0; } |