summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target
diff options
context:
space:
mode:
authorSimon Pilgrim <llvm-dev@redking.me.uk>2017-02-24 10:15:29 +0000
committerSimon Pilgrim <llvm-dev@redking.me.uk>2017-02-24 10:15:29 +0000
commitaed352273e8deddea35a6f9b8d4dbc9b98ba04c0 (patch)
tree6eddcff36bd08acdb134d0c0aed9f4274d71b5ae /llvm/lib/Target
parent4a705e7ea0cb911d9ec2933b99f5d1f7c1ba9ad3 (diff)
downloadbcm5719-llvm-aed352273e8deddea35a6f9b8d4dbc9b98ba04c0.tar.gz
bcm5719-llvm-aed352273e8deddea35a6f9b8d4dbc9b98ba04c0.zip
[APInt] Add APInt::setBits() method to set all bits in range
The current pattern for setting bits in range is typically: Mask |= APInt::getBitsSet(MaskSizeInBits, LoPos, HiPos); Which can be particularly slow for large APInts (MaskSizeInBits > 64) as they require the allocation memory for the temporary variable. This is one of the key compile time issues identified in PR32037. This patch adds the APInt::setBits() helper method which avoids the temporary memory allocation completely, this first implementation uses setBit() internally instead but already significantly reduces the regression in PR32037 (~10% drop). Additional optimization may be possible. I investigated whether there is need for APInt::clearBits() and APInt::flipBits() equivalents but haven't seen these patterns to be particularly common, but reusing the code would be trivial. Differential Revision: https://reviews.llvm.org/D30265 llvm-svn: 296102
Diffstat (limited to 'llvm/lib/Target')
-rw-r--r--llvm/lib/Target/X86/X86ISelLowering.cpp12
-rw-r--r--llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp3
2 files changed, 6 insertions, 9 deletions
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 720f93a4fbe..6b404a498e3 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -5236,8 +5236,7 @@ static bool getTargetConstantBitsFromNode(SDValue Op, unsigned EltSizeInBits,
return false;
unsigned CstSizeInBits = Cst->getType()->getPrimitiveSizeInBits();
if (isa<UndefValue>(Cst)) {
- unsigned HiBits = BitOffset + CstSizeInBits;
- Undefs |= APInt::getBitsSet(SizeInBits, BitOffset, HiBits);
+ Undefs.setBits(BitOffset, BitOffset + CstSizeInBits);
return true;
}
if (auto *CInt = dyn_cast<ConstantInt>(Cst)) {
@@ -5258,8 +5257,7 @@ static bool getTargetConstantBitsFromNode(SDValue Op, unsigned EltSizeInBits,
const SDValue &Src = Op.getOperand(i);
unsigned BitOffset = i * SrcEltSizeInBits;
if (Src.isUndef()) {
- unsigned HiBits = BitOffset + SrcEltSizeInBits;
- UndefBits |= APInt::getBitsSet(SizeInBits, BitOffset, HiBits);
+ UndefBits.setBits(BitOffset, BitOffset + SrcEltSizeInBits);
continue;
}
auto *Cst = cast<ConstantSDNode>(Src);
@@ -26353,11 +26351,11 @@ void X86TargetLowering::computeKnownBitsForTargetNode(const SDValue Op,
break;
LLVM_FALLTHROUGH;
case X86ISD::SETCC:
- KnownZero |= APInt::getHighBitsSet(BitWidth, BitWidth - 1);
+ KnownZero.setBits(1, BitWidth);
break;
case X86ISD::MOVMSK: {
unsigned NumLoBits = Op.getOperand(0).getValueType().getVectorNumElements();
- KnownZero = APInt::getHighBitsSet(BitWidth, BitWidth - NumLoBits);
+ KnownZero.setBits(NumLoBits, BitWidth);
break;
}
case X86ISD::VZEXT: {
@@ -26374,7 +26372,7 @@ void X86TargetLowering::computeKnownBitsForTargetNode(const SDValue Op,
DAG.computeKnownBits(N0, KnownZero, KnownOne, DemandedSrcElts, Depth + 1);
KnownOne = KnownOne.zext(BitWidth);
KnownZero = KnownZero.zext(BitWidth);
- KnownZero |= APInt::getHighBitsSet(BitWidth, BitWidth - InBitWidth);
+ KnownZero.setBits(InBitWidth, BitWidth);
break;
}
}
diff --git a/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp b/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp
index 4d278d4b05a..41ad0971461 100644
--- a/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp
+++ b/llvm/lib/Target/X86/X86ShuffleDecodeConstantPool.cpp
@@ -60,8 +60,7 @@ static bool extractConstantMask(const Constant *C, unsigned MaskEltSizeInBits,
unsigned BitOffset = i * CstEltSizeInBits;
if (isa<UndefValue>(COp)) {
- unsigned HiBits = BitOffset + CstEltSizeInBits;
- UndefBits |= APInt::getBitsSet(CstSizeInBits, BitOffset, HiBits);
+ UndefBits.setBits(BitOffset, BitOffset + CstEltSizeInBits);
continue;
}
OpenPOWER on IntegriCloud