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

Huihui Zhang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 3 16:19:31 PST 2019


huihuiz updated this revision to Diff 232009.
huihuiz added a comment.

Addressed review feedback.


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 -instcombine -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;
 
+  // Should not iterate over scalable vector, as num element is known at
+  // runtime.
+  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.232009.patch
Type: text/x-patch
Size: 1516 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191204/2cf454e2/attachment.bin>


More information about the llvm-commits mailing list