diff options
author | Chris Lattner <sabre@nondot.org> | 2012-01-24 14:31:22 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2012-01-24 14:31:22 +0000 |
commit | bec2d03c4d774e67ebc586b3a00792d996f26140 (patch) | |
tree | 64002a805c19740ecd831da6a88cd94d054deac4 /lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp | |
parent | 29cc6cb4d1aa22f0a27edf4e5b363071a83a65d8 (diff) |
basic instcombine support for CDS.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148806 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp')
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp index 91a48a8473..ed9442511d 100644 --- a/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp +++ b/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp @@ -855,23 +855,36 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts, return NewCP != CV ? NewCP : 0; } - if (isa<ConstantAggregateZero>(V)) { - // Simplify the CAZ to a ConstantVector where the non-demanded elements are - // set to undef. + if (ConstantDataVector *CDV = dyn_cast<ConstantDataVector>(V)) { + // Check if this is identity. If so, return 0 since we are not simplifying + // anything. + if (DemandedElts.isAllOnesValue()) + return 0; + + // Simplify to a ConstantVector where the non-demanded elements are undef. + Constant *Undef = UndefValue::get(CDV->getElementType()); + SmallVector<Constant*, 16> Elts; + for (unsigned i = 0; i != VWidth; ++i) + Elts.push_back(DemandedElts[i] ? CDV->getElementAsConstant(i) : Undef); + UndefElts = DemandedElts ^ EltMask; + return ConstantVector::get(Elts); + + } + + if (ConstantAggregateZero *CAZ = dyn_cast<ConstantAggregateZero>(V)) { // Check if this is identity. If so, return 0 since we are not simplifying // anything. if (DemandedElts.isAllOnesValue()) return 0; - Type *EltTy = cast<VectorType>(V->getType())->getElementType(); - Constant *Zero = Constant::getNullValue(EltTy); - Constant *Undef = UndefValue::get(EltTy); - std::vector<Constant*> Elts; - for (unsigned i = 0; i != VWidth; ++i) { - Constant *Elt = DemandedElts[i] ? Zero : Undef; - Elts.push_back(Elt); - } + // Simplify the CAZ to a ConstantVector where the non-demanded elements are + // set to undef. + Constant *Zero = CAZ->getSequentialElement(); + Constant *Undef = UndefValue::get(Zero->getType()); + SmallVector<Constant*, 16> Elts; + for (unsigned i = 0; i != VWidth; ++i) + Elts.push_back(DemandedElts[i] ? Zero : Undef); UndefElts = DemandedElts ^ EltMask; return ConstantVector::get(Elts); } |