[llvm] r295848 - [X86][SSE] getTargetConstantBitsFromNode - insert constant bits directly into masks.
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 22 07:38:14 PST 2017
Author: rksimon
Date: Wed Feb 22 09:38:13 2017
New Revision: 295848
URL: http://llvm.org/viewvc/llvm-project?rev=295848&view=rev
Log:
[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.
Modified:
llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=295848&r1=295847&r2=295848&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Wed Feb 22 09:38:13 2017
@@ -5205,31 +5205,30 @@ static bool getTargetConstantBitsFromNod
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 getTargetConstantBitsFromNod
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 getTargetConstantBitsFromNod
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);
More information about the llvm-commits
mailing list