Skip to content

Commit 381d3c5

Browse files
committed
[ConstantFold][SVE] Skip scalable vectors in ConstantFoldInsertElementInstruction.
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
1 parent 7599095 commit 381d3c5

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

llvm/lib/IR/ConstantFold.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,12 @@ Constant *llvm::ConstantFoldInsertElementInstruction(Constant *Val,
833833
ConstantInt *CIdx = dyn_cast<ConstantInt>(Idx);
834834
if (!CIdx) return nullptr;
835835

836+
// Do not iterate on scalable vector. The num of elements is unknown at
837+
// compile-time.
838+
VectorType *ValTy = cast<VectorType>(Val->getType());
839+
if (ValTy->isScalable())
840+
return nullptr;
841+
836842
unsigned NumElts = Val->getType()->getVectorNumElements();
837843
if (CIdx->uge(NumElts))
838844
return UndefValue::get(Val->getType());
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt < %s -constprop -S | FileCheck %s
3+
4+
5+
define <4 x i32> @insertelement_fixedlength_constant() {
6+
; CHECK-LABEL: @insertelement_fixedlength_constant(
7+
; CHECK-NEXT: ret <4 x i32> <i32 1, i32 undef, i32 undef, i32 undef>
8+
;
9+
%i = insertelement <4 x i32> undef, i32 1, i32 0
10+
ret <4 x i32> %i
11+
}
12+
13+
define <vscale x 4 x i32> @insertelement_scalable_constant() {
14+
; CHECK-LABEL: @insertelement_scalable_constant(
15+
; CHECK-NEXT: ret <vscale x 4 x i32> insertelement (<vscale x 4 x i32> undef, i32 1, i32 0)
16+
;
17+
%i = insertelement <vscale x 4 x i32> undef, i32 1, i32 0
18+
ret <vscale x 4 x i32> %i
19+
}

0 commit comments

Comments
 (0)