[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 14:08:15 PST 2019


huihuiz created this revision.
huihuiz added reviewers: huntergr, sdesmalen, spatel, lebedev.ri, apazos, efriedma, willlovett.
Herald added subscribers: psnobl, rkruppe, hiraditya, tschuett.
Herald added a project: LLVM.

Should not constant fold insertelement instruction for scalable vector type.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70985

Files:
  llvm/lib/IR/ConstantFold.cpp
  llvm/test/Transforms/InstCombine/insertelement.ll


Index: llvm/test/Transforms/InstCombine/insertelement.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/InstCombine/insertelement.ll
@@ -0,0 +1,73 @@
+; 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 <4 x i32> @insertelement_fixedlength_val1(<4 x i32> %val) {
+; CHECK-LABEL: @insertelement_fixedlength_val1(
+; CHECK-NEXT:    [[I:%.*]] = insertelement <4 x i32> [[VAL:%.*]], i32 1, i32 0
+; CHECK-NEXT:    ret <4 x i32> [[I]]
+;
+  %i = insertelement <4 x i32> %val, i32 1, i32 0
+  ret <4 x i32> %i
+}
+
+define <4 x i32> @insertelement_fixedlength_val2(i32 %val) {
+; CHECK-LABEL: @insertelement_fixedlength_val2(
+; CHECK-NEXT:    [[I:%.*]] = insertelement <4 x i32> undef, i32 [[VAL:%.*]], i32 0
+; CHECK-NEXT:    ret <4 x i32> [[I]]
+;
+  %i = insertelement <4 x i32> undef, i32 %val, i32 0
+  ret <4 x i32> %i
+}
+
+define <4 x i32> @insertelement_fixedlength_val3(i32 %val) {
+; CHECK-LABEL: @insertelement_fixedlength_val3(
+; CHECK-NEXT:    [[I:%.*]] = insertelement <4 x i32> undef, i32 1, i32 [[VAL:%.*]]
+; CHECK-NEXT:    ret <4 x i32> [[I]]
+;
+  %i = insertelement <4 x i32> undef, i32 1, i32 %val
+  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
+}
+
+define <vscale x 4 x i32> @insertelement_scalable_val1(<vscale x 4 x i32> %val) {
+; CHECK-LABEL: @insertelement_scalable_val1(
+; CHECK-NEXT:    [[I:%.*]] = insertelement <vscale x 4 x i32> [[VAL:%.*]], i32 1, i32 0
+; CHECK-NEXT:    ret <vscale x 4 x i32> [[I]]
+;
+  %i = insertelement <vscale x 4 x i32> %val, i32 1, i32 0
+  ret <vscale x 4 x i32> %i
+}
+
+define <vscale x 4 x i32> @insertelement_scalable_val2(i32 %val) {
+; CHECK-LABEL: @insertelement_scalable_val2(
+; CHECK-NEXT:    [[I:%.*]] = insertelement <vscale x 4 x i32> undef, i32 [[VAL:%.*]], i32 0
+; CHECK-NEXT:    ret <vscale x 4 x i32> [[I]]
+;
+  %i = insertelement <vscale x 4 x i32> undef, i32 %val, i32 0
+  ret <vscale x 4 x i32> %i
+}
+
+define <vscale x 4 x i32> @insertelement_scalable_val3(i32 %val) {
+; CHECK-LABEL: @insertelement_scalable_val3(
+; CHECK-NEXT:    [[I:%.*]] = insertelement <vscale x 4 x i32> undef, i32 1, i32 [[VAL:%.*]]
+; CHECK-NEXT:    ret <vscale x 4 x i32> [[I]]
+;
+  %i = insertelement <vscale x 4 x i32> undef, i32 1, i32 %val
+  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.231985.patch
Type: text/x-patch
Size: 3530 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191203/d7f963d5/attachment.bin>


More information about the llvm-commits mailing list