aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Constants.cpp
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@sifive.com>2022-09-26 14:53:06 -0700
committerCraig Topper <craig.topper@sifive.com>2022-09-26 14:55:15 -0700
commit90b695d1f24cd9d6832acf9c7c64ec28a45bb4a1 (patch)
tree0040554be6b88707c21bb45f84021bae01ac4470 /llvm/lib/IR/Constants.cpp
parent0ca1051bfc6e9548763f0a52641733393c33a427 (diff)
downloadllvm-90b695d1f24cd9d6832acf9c7c64ec28a45bb4a1.zip
llvm-90b695d1f24cd9d6832acf9c7c64ec28a45bb4a1.tar.gz
llvm-90b695d1f24cd9d6832acf9c7c64ec28a45bb4a1.tar.bz2
[IR][InstCombine] Support scalable vector splats ConstantExprs in Constant::getUniqueInteger().
I've left the getAggregateElement as a fast path for non-ConstantExprs to avoid a call to getSplatValue in release builds. Fixes PR57989. Reviewed By: spatel Differential Revision: https://reviews.llvm.org/D134670
Diffstat (limited to 'llvm/lib/IR/Constants.cpp')
-rw-r--r--llvm/lib/IR/Constants.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index 6eecbb0..d6a87c8 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -1682,6 +1682,11 @@ Constant *ConstantVector::getSplatValue(bool AllowUndefs) const {
const APInt &Constant::getUniqueInteger() const {
if (const ConstantInt *CI = dyn_cast<ConstantInt>(this))
return CI->getValue();
+ // Scalable vectors can use a ConstantExpr to build a splat.
+ if (isa<ConstantExpr>(this))
+ return cast<ConstantInt>(this->getSplatValue())->getValue();
+ // For non-ConstantExpr we use getAggregateElement as a fast path to avoid
+ // calling getSplatValue in release builds.
assert(this->getSplatValue() && "Doesn't contain a unique integer!");
const Constant *C = this->getAggregateElement(0U);
assert(C && isa<ConstantInt>(C) && "Not a vector of numbers!");