[llvm] 381d3c5 - [ConstantFold][SVE] Skip scalable vectors in ConstantFoldInsertElementInstruction.

Huihui Zhang via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 5 19:44:24 PST 2019


Author: Huihui Zhang
Date: 2019-12-05T19:43:19-08:00
New Revision: 381d3c5c45c55c00f8d561eaff03b460953ca5c0

URL: https://github.com/llvm/llvm-project/commit/381d3c5c45c55c00f8d561eaff03b460953ca5c0
DIFF: https://github.com/llvm/llvm-project/commit/381d3c5c45c55c00f8d561eaff03b460953ca5c0.diff

LOG: [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

Added: 
    llvm/test/Analysis/ConstantFolding/insertelement.ll

Modified: 
    llvm/lib/IR/ConstantFold.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index f6dbe9b5ea93..bf01f9f2ae67 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -833,6 +833,12 @@ Constant *llvm::ConstantFoldInsertElementInstruction(Constant *Val,
   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());

diff  --git a/llvm/test/Analysis/ConstantFolding/insertelement.ll b/llvm/test/Analysis/ConstantFolding/insertelement.ll
new file mode 100644
index 000000000000..960042acfb46
--- /dev/null
+++ b/llvm/test/Analysis/ConstantFolding/insertelement.ll
@@ -0,0 +1,19 @@
+; 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
+}


        


More information about the llvm-commits mailing list