]> granicus.if.org Git - llvm/commit
[APInt] Add APInt::setBits() method to set all bits in range
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Fri, 24 Feb 2017 10:15:29 +0000 (10:15 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Fri, 24 Feb 2017 10:15:29 +0000 (10:15 +0000)
commit02e6cb0f2d29f8a82cd682a18a2563c3c753eae3
treeab9e61df6b20764c1dd94c1aed9d9fd6f71a3bec
parentdde79d7c7b108ad1636d3478d2613e8b4217744f
[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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296102 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/ADT/APInt.h
lib/Support/APInt.cpp
lib/Target/X86/X86ISelLowering.cpp
lib/Target/X86/X86ShuffleDecodeConstantPool.cpp
unittests/ADT/APIntTest.cpp