[PATCH] D70985: [ConstantFold][SVE] Skip scalable vectors in ConstantFoldInsertElementInstruction.

Huihui Zhang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 5 19:48:23 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rG381d3c5c45c5: [ConstantFold][SVE] Skip scalable vectors in… (authored by huihuiz).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70985/new/

https://reviews.llvm.org/D70985

Files:
  llvm/lib/IR/ConstantFold.cpp
  llvm/test/Analysis/ConstantFolding/insertelement.ll


Index: llvm/test/Analysis/ConstantFolding/insertelement.ll
===================================================================
--- /dev/null
+++ 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
+}
Index: llvm/lib/IR/ConstantFold.cpp
===================================================================
--- llvm/lib/IR/ConstantFold.cpp
+++ llvm/lib/IR/ConstantFold.cpp
@@ -833,6 +833,12 @@
   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());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70985.232490.patch
Type: text/x-patch
Size: 1520 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191206/8dc1a6d0/attachment.bin>


More information about the llvm-commits mailing list