diff options
author | Michael Ilseman <milseman@apple.com> | 2013-02-11 21:41:44 +0000 |
---|---|---|
committer | Michael Ilseman <milseman@apple.com> | 2013-02-11 21:41:44 +0000 |
commit | 9c213cc3c31da04a08a8e00a3395ac33d3d18536 (patch) | |
tree | dffeb85fad955ab9ec126b37e41ea2998431807f /lib/Transforms | |
parent | 71490fa946f750fb3afe7228a32d31d401d4c1d8 (diff) | |
download | external_llvm-9c213cc3c31da04a08a8e00a3395ac33d3d18536.zip external_llvm-9c213cc3c31da04a08a8e00a3395ac33d3d18536.tar.gz external_llvm-9c213cc3c31da04a08a8e00a3395ac33d3d18536.tar.bz2 |
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
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineCasts.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineCasts.cpp b/lib/Transforms/InstCombine/InstCombineCasts.cpp index 98fd05a..fbc259b 100644 --- a/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -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); } } |