diff options
author | Thomas Raoux <thomasraoux@google.com> | 2020-03-30 10:36:21 -0700 |
---|---|---|
committer | Thomas Raoux <thomasraoux@google.com> | 2020-03-30 11:27:09 -0700 |
commit | 3ea0774b13a538759aa1a68f30130d18ddb0d3f2 (patch) | |
tree | f19bd3ecf25f6fd958a60bc909e185b98b4eea2f /llvm/lib/IR/Constants.cpp | |
parent | 8242509a49e019c0279305d152c7ab2b9cdc2d0d (diff) | |
download | llvm-3ea0774b13a538759aa1a68f30130d18ddb0d3f2.zip llvm-3ea0774b13a538759aa1a68f30130d18ddb0d3f2.tar.gz llvm-3ea0774b13a538759aa1a68f30130d18ddb0d3f2.tar.bz2 |
[ConstantFold][NFC] Compile time optimization for large vectors
Optimize the common case of splat vector constant. For large vector
going through all elements is expensive. For splatr/broadcast cases we
can skip going through all elements.
Differential Revision: https://reviews.llvm.org/D76664
Diffstat (limited to 'llvm/lib/IR/Constants.cpp')
-rw-r--r-- | llvm/lib/IR/Constants.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index bde4c07..e001b52 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -2891,7 +2891,7 @@ bool ConstantDataSequential::isCString() const { return Str.drop_back().find(0) == StringRef::npos; } -bool ConstantDataVector::isSplat() const { +bool ConstantDataVector::isSplatData() const { const char *Base = getRawDataValues().data(); // Compare elements 1+ to the 0'th element. @@ -2903,6 +2903,14 @@ bool ConstantDataVector::isSplat() const { return true; } +bool ConstantDataVector::isSplat() const { + if (!IsSplatSet) { + IsSplatSet = true; + IsSplat = isSplatData(); + } + return IsSplat; +} + Constant *ConstantDataVector::getSplatValue() const { // If they're all the same, return the 0th one as a representative. return isSplat() ? getElementAsConstant(0) : nullptr; |