mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-25 13:24:46 +00:00
Simplify demanded bits of select sources where the condition is a constant vector
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160835 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -899,5 +899,16 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
|
||||
return &SI;
|
||||
}
|
||||
|
||||
if (VectorType* VecTy = dyn_cast<VectorType>(SI.getType())) {
|
||||
unsigned VWidth = VecTy->getNumElements();
|
||||
APInt UndefElts(VWidth, 0);
|
||||
APInt AllOnesEltMask(APInt::getAllOnesValue(VWidth));
|
||||
if (Value *V = SimplifyDemandedVectorElts(&SI, AllOnesEltMask, UndefElts)) {
|
||||
if (V != &SI)
|
||||
return ReplaceInstUsesWith(SI, V);
|
||||
return &SI;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -989,6 +989,29 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Instruction::Select: {
|
||||
APInt LeftDemanded(DemandedElts), RightDemanded(DemandedElts);
|
||||
if (ConstantVector* CV = dyn_cast<ConstantVector>(I->getOperand(0))) {
|
||||
for (unsigned i = 0; i < VWidth; i++) {
|
||||
if (CV->getAggregateElement(i)->isNullValue())
|
||||
LeftDemanded.clearBit(i);
|
||||
else
|
||||
RightDemanded.clearBit(i);
|
||||
}
|
||||
}
|
||||
|
||||
TmpV = SimplifyDemandedVectorElts(I->getOperand(1), LeftDemanded,
|
||||
UndefElts, Depth+1);
|
||||
if (TmpV) { I->setOperand(1, TmpV); MadeChange = true; }
|
||||
|
||||
TmpV = SimplifyDemandedVectorElts(I->getOperand(2), RightDemanded,
|
||||
UndefElts2, Depth+1);
|
||||
if (TmpV) { I->setOperand(2, TmpV); MadeChange = true; }
|
||||
|
||||
// Output elements are undefined if both are undefined.
|
||||
UndefElts &= UndefElts2;
|
||||
break;
|
||||
}
|
||||
case Instruction::BitCast: {
|
||||
// Vector->vector casts only.
|
||||
VectorType *VTy = dyn_cast<VectorType>(I->getOperand(0)->getType());
|
||||
|
Reference in New Issue
Block a user