[X86][SSE] getTargetConstantBitsFromNode - insert constant bits directly into masks.

Minor optimization, don't create temporary mask APInts that are just going to be OR'd into the accumulate masks - insert directly instead.

llvm-svn: 295848
This commit is contained in:
Simon Pilgrim 2017-02-22 15:38:13 +00:00
parent deb30e8278
commit 13cdd57964
1 changed files with 15 additions and 18 deletions

View File

@ -5205,31 +5205,30 @@ static bool getTargetConstantBitsFromNode(SDValue Op, unsigned EltSizeInBits,
if (UndefEltBits.getBoolValue() && !AllowPartialUndefs)
return false;
APInt Bits = MaskBits.lshr(i * EltSizeInBits);
Bits = Bits.zextOrTrunc(EltSizeInBits);
APInt Bits = MaskBits.lshr(i * EltSizeInBits).zextOrTrunc(EltSizeInBits);
EltBits[i] = Bits.getZExtValue();
}
return true;
};
auto ExtractConstantBits = [SizeInBits](const Constant *Cst, APInt &Mask,
APInt &Undefs) {
// Collect constant bits and insert into mask/undef bit masks.
auto CollectConstantBits = [SizeInBits](const Constant *Cst, APInt &Mask,
APInt &Undefs, unsigned BitOffset) {
if (!Cst)
return false;
unsigned CstSizeInBits = Cst->getType()->getPrimitiveSizeInBits();
if (isa<UndefValue>(Cst)) {
Mask = APInt::getNullValue(SizeInBits);
Undefs = APInt::getLowBitsSet(SizeInBits, CstSizeInBits);
unsigned HiBits = BitOffset + CstSizeInBits;
Undefs |= APInt::getBitsSet(SizeInBits, BitOffset, HiBits);
return true;
}
if (auto *CInt = dyn_cast<ConstantInt>(Cst)) {
Mask = CInt->getValue().zextOrTrunc(SizeInBits);
Undefs = APInt::getNullValue(SizeInBits);
Mask |= CInt->getValue().zextOrTrunc(SizeInBits).shl(BitOffset);
return true;
}
if (auto *CFP = dyn_cast<ConstantFP>(Cst)) {
Mask = CFP->getValueAPF().bitcastToAPInt().zextOrTrunc(SizeInBits);
Undefs = APInt::getNullValue(SizeInBits);
APInt CstBits = CFP->getValueAPF().bitcastToAPInt();
Mask |= CstBits.zextOrTrunc(SizeInBits).shl(BitOffset);
return true;
}
return false;
@ -5259,13 +5258,10 @@ static bool getTargetConstantBitsFromNode(SDValue Op, unsigned EltSizeInBits,
return false;
unsigned CstEltSizeInBits = CstTy->getScalarSizeInBits();
for (unsigned i = 0, e = CstTy->getVectorNumElements(); i != e; ++i) {
APInt Bits, Undefs;
if (!ExtractConstantBits(Cst->getAggregateElement(i), Bits, Undefs))
for (unsigned i = 0, e = CstTy->getVectorNumElements(); i != e; ++i)
if (!CollectConstantBits(Cst->getAggregateElement(i), MaskBits, UndefBits,
i * CstEltSizeInBits))
return false;
MaskBits |= Bits.shl(i * CstEltSizeInBits);
UndefBits |= Undefs.shl(i * CstEltSizeInBits);
}
return SplitBitData();
}
@ -5274,8 +5270,9 @@ static bool getTargetConstantBitsFromNode(SDValue Op, unsigned EltSizeInBits,
if (Op.getOpcode() == X86ISD::VBROADCAST &&
EltSizeInBits <= SrcEltSizeInBits) {
if (auto *Broadcast = getTargetConstantFromNode(Op.getOperand(0))) {
APInt Bits, Undefs;
if (ExtractConstantBits(Broadcast, Bits, Undefs)) {
APInt Bits(SizeInBits, 0);
APInt Undefs(SizeInBits, 0);
if (CollectConstantBits(Broadcast, Bits, Undefs, 0)) {
for (unsigned i = 0; i != NumSrcElts; ++i) {
MaskBits |= Bits.shl(i * SrcEltSizeInBits);
UndefBits |= Undefs.shl(i * SrcEltSizeInBits);