mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-26 05:25:47 +00:00
basic instcombine support for CDS.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148806 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -855,23 +855,36 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
|
|||||||
return NewCP != CV ? NewCP : 0;
|
return NewCP != CV ? NewCP : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isa<ConstantAggregateZero>(V)) {
|
if (ConstantDataVector *CDV = dyn_cast<ConstantDataVector>(V)) {
|
||||||
// Simplify the CAZ to a ConstantVector where the non-demanded elements are
|
|
||||||
// set to undef.
|
|
||||||
|
|
||||||
// Check if this is identity. If so, return 0 since we are not simplifying
|
// Check if this is identity. If so, return 0 since we are not simplifying
|
||||||
// anything.
|
// anything.
|
||||||
if (DemandedElts.isAllOnesValue())
|
if (DemandedElts.isAllOnesValue())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
Type *EltTy = cast<VectorType>(V->getType())->getElementType();
|
// Simplify to a ConstantVector where the non-demanded elements are undef.
|
||||||
Constant *Zero = Constant::getNullValue(EltTy);
|
Constant *Undef = UndefValue::get(CDV->getElementType());
|
||||||
Constant *Undef = UndefValue::get(EltTy);
|
|
||||||
std::vector<Constant*> Elts;
|
SmallVector<Constant*, 16> Elts;
|
||||||
for (unsigned i = 0; i != VWidth; ++i) {
|
for (unsigned i = 0; i != VWidth; ++i)
|
||||||
Constant *Elt = DemandedElts[i] ? Zero : Undef;
|
Elts.push_back(DemandedElts[i] ? CDV->getElementAsConstant(i) : Undef);
|
||||||
Elts.push_back(Elt);
|
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;
|
||||||
|
|
||||||
|
// 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;
|
UndefElts = DemandedElts ^ EltMask;
|
||||||
return ConstantVector::get(Elts);
|
return ConstantVector::get(Elts);
|
||||||
}
|
}
|
||||||
|
@@ -16,7 +16,8 @@
|
|||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
/// CheapToScalarize - Return true if the value is cheaper to scalarize than it
|
/// CheapToScalarize - Return true if the value is cheaper to scalarize than it
|
||||||
/// is to leave as a vector operation.
|
/// is to leave as a vector operation. isConstant indicates whether we're
|
||||||
|
/// extracting one known element. If false we're extracting a variable index.
|
||||||
static bool CheapToScalarize(Value *V, bool isConstant) {
|
static bool CheapToScalarize(Value *V, bool isConstant) {
|
||||||
if (isa<ConstantAggregateZero>(V))
|
if (isa<ConstantAggregateZero>(V))
|
||||||
return true;
|
return true;
|
||||||
@@ -335,10 +336,14 @@ static Value *CollectShuffleElements(Value *V, std::vector<Constant*> &Mask,
|
|||||||
if (isa<UndefValue>(V)) {
|
if (isa<UndefValue>(V)) {
|
||||||
Mask.assign(NumElts, UndefValue::get(Type::getInt32Ty(V->getContext())));
|
Mask.assign(NumElts, UndefValue::get(Type::getInt32Ty(V->getContext())));
|
||||||
return V;
|
return V;
|
||||||
} else if (isa<ConstantAggregateZero>(V)) {
|
}
|
||||||
|
|
||||||
|
if (isa<ConstantAggregateZero>(V)) {
|
||||||
Mask.assign(NumElts, ConstantInt::get(Type::getInt32Ty(V->getContext()),0));
|
Mask.assign(NumElts, ConstantInt::get(Type::getInt32Ty(V->getContext()),0));
|
||||||
return V;
|
return V;
|
||||||
} else if (InsertElementInst *IEI = dyn_cast<InsertElementInst>(V)) {
|
}
|
||||||
|
|
||||||
|
if (InsertElementInst *IEI = dyn_cast<InsertElementInst>(V)) {
|
||||||
// If this is an insert of an extract from some other vector, include it.
|
// If this is an insert of an extract from some other vector, include it.
|
||||||
Value *VecOp = IEI->getOperand(0);
|
Value *VecOp = IEI->getOperand(0);
|
||||||
Value *ScalarOp = IEI->getOperand(1);
|
Value *ScalarOp = IEI->getOperand(1);
|
||||||
|
Reference in New Issue
Block a user