[PATCH] D134670: [IR][InstCombine] Support scalable vector splats ConstantExprs in Constant::getUniqueInteger().
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 26 14:58:37 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG90b695d1f24c: [IR][InstCombine] Support scalable vector splats ConstantExprs in Constant… (authored by craig.topper).
Changed prior to commit:
https://reviews.llvm.org/D134670?vs=463004&id=463033#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D134670/new/
https://reviews.llvm.org/D134670
Files:
llvm/lib/IR/Constants.cpp
llvm/test/Transforms/InstCombine/select.ll
Index: llvm/test/Transforms/InstCombine/select.ll
===================================================================
--- llvm/test/Transforms/InstCombine/select.ll
+++ llvm/test/Transforms/InstCombine/select.ll
@@ -3395,3 +3395,16 @@
%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
+}
Index: llvm/lib/IR/Constants.cpp
===================================================================
--- llvm/lib/IR/Constants.cpp
+++ llvm/lib/IR/Constants.cpp
@@ -1682,6 +1682,11 @@
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!");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134670.463033.patch
Type: text/x-patch
Size: 2052 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220926/b317ba1b/attachment.bin>
More information about the llvm-commits
mailing list