Summary:
Should not constant fold insertelement instruction for scalable vector type.
Reviewers: huntergr, sdesmalen, spatel, levedev.ri, apazos, efriedma, willlovett
Reviewed By: efriedma, spatel
Subscribers: tschuett, hiraditya, rkruppe, psnobl, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D70985
ConstantInt *CIdx = dyn_cast<ConstantInt>(Idx);
if (!CIdx) return nullptr;
+ // Do not iterate on scalable vector. The num of elements is unknown at
+ // compile-time.
+ VectorType *ValTy = cast<VectorType>(Val->getType());
+ if (ValTy->isScalable())
+ return nullptr;
+
unsigned NumElts = Val->getType()->getVectorNumElements();
if (CIdx->uge(NumElts))
return UndefValue::get(Val->getType());
--- /dev/null
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -constprop -S | FileCheck %s
+
+
+define <4 x i32> @insertelement_fixedlength_constant() {
+; CHECK-LABEL: @insertelement_fixedlength_constant(
+; CHECK-NEXT: ret <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef>
+;
+ %i = insertelement <4 x i32> undef, i32 1, i32 0
+ ret <4 x i32> %i
+}
+
+define <vscale x 4 x i32> @insertelement_scalable_constant() {
+; CHECK-LABEL: @insertelement_scalable_constant(
+; CHECK-NEXT: ret <vscale x 4 x i32> insertelement (<vscale x 4 x i32> undef, i32 1, i32 0)
+;
+ %i = insertelement <vscale x 4 x i32> undef, i32 1, i32 0
+ ret <vscale x 4 x i32> %i
+}