Optimization: bitcast (<1 x ...> insertelement ..., X, ...) to ... ==> bitcast X to ...

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174905 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Michael Ilseman 2013-02-11 21:41:44 +00:00
parent 71490fa946
commit 9c213cc3c3
2 changed files with 23 additions and 6 deletions

View File

@ -1738,11 +1738,22 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) {
}
if (VectorType *SrcVTy = dyn_cast<VectorType>(SrcTy)) {
if (SrcVTy->getNumElements() == 1 && !DestTy->isVectorTy()) {
Value *Elem =
Builder->CreateExtractElement(Src,
Constant::getNullValue(Type::getInt32Ty(CI.getContext())));
return CastInst::Create(Instruction::BitCast, Elem, DestTy);
if (SrcVTy->getNumElements() == 1) {
// If our destination is not a vector, then make this a straight
// scalar-scalar cast.
if (!DestTy->isVectorTy()) {
Value *Elem =
Builder->CreateExtractElement(Src,
Constant::getNullValue(Type::getInt32Ty(CI.getContext())));
return CastInst::Create(Instruction::BitCast, Elem, DestTy);
}
// Otherwise, see if our source is an insert. If so, then use the scalar
// component directly.
if (InsertElementInst *IEI =
dyn_cast<InsertElementInst>(CI.getOperand(0)))
return CastInst::Create(Instruction::BitCast, IEI->getOperand(1),
DestTy);
}
}

View File

@ -137,4 +137,10 @@ define i32 @All111(i32 %in) {
; CHECK: ret i32 0
}
define <2 x i16> @BitcastInsert(i32 %a) {
%v = insertelement <1 x i32> undef, i32 %a, i32 0
%r = bitcast <1 x i32> %v to <2 x i16>
ret <2 x i16> %r
; CHECK: @BitcastInsert
; CHECK: bitcast i32 %a to <2 x i16>
}