[llvm] 90b695d - [IR][InstCombine] Support scalable vector splats ConstantExprs in Constant::getUniqueInteger().
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 26 14:58:29 PDT 2022
Author: Craig Topper
Date: 2022-09-26T14:55:15-07:00
New Revision: 90b695d1f24cd9d6832acf9c7c64ec28a45bb4a1
URL: https://github.com/llvm/llvm-project/commit/90b695d1f24cd9d6832acf9c7c64ec28a45bb4a1
DIFF: https://github.com/llvm/llvm-project/commit/90b695d1f24cd9d6832acf9c7c64ec28a45bb4a1.diff
LOG: [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
Added:
Modified:
llvm/lib/IR/Constants.cpp
llvm/test/Transforms/InstCombine/select.ll
Removed:
################################################################################
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index 6eecbb04f2e85..d6a87c868b847 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!");
diff --git a/llvm/test/Transforms/InstCombine/select.ll b/llvm/test/Transforms/InstCombine/select.ll
index 57aada15b936b..918b88a8374e8 100644
--- a/llvm/test/Transforms/InstCombine/select.ll
+++ b/llvm/test/Transforms/InstCombine/select.ll
@@ -3395,3 +3395,16 @@ define i32 @select_cond_not_cond_cond2(i1 %cond) {
%v = select i1 %cond, i32 %s, i32 %z
ret i32 %v
}
+
+; This previously crashed due to Constant::getUniqueInteger not handling
+; scalable vector splat ConstantExprs.
+define <vscale x 2 x i32> @and_constant_select_svec(<vscale x 2 x i32> %x, <vscale x 2 x i1> %cond) {
+; CHECK-LABEL: @and_constant_select_svec(
+; CHECK-NEXT: [[A:%.*]] = and <vscale x 2 x i32> [[X:%.*]], shufflevector (<vscale x 2 x i32> insertelement (<vscale x 2 x i32> poison, i32 1, i32 0), <vscale x 2 x i32> poison, <vscale x 2 x i32> zeroinitializer)
+; CHECK-NEXT: [[B:%.*]] = select <vscale x 2 x i1> [[COND:%.*]], <vscale x 2 x i32> [[A]], <vscale x 2 x i32> [[X]]
+; CHECK-NEXT: ret <vscale x 2 x i32> [[B]]
+;
+ %a = and <vscale x 2 x i32> %x, shufflevector (<vscale x 2 x i32> insertelement (<vscale x 2 x i32> poison, i32 1, i32 0), <vscale x 2 x i32> poison, <vscale x 2 x i32> zeroinitializer)
+ %b = select <vscale x 2 x i1> %cond, <vscale x 2 x i32> %a, <vscale x 2 x i32> %x
+ ret <vscale x 2 x i32> %b
+}
More information about the llvm-commits
mailing list