[PATCH] D123413: [IR] Allow constant folding (insertelement <vscale x 2 x i32> zeroinitializer, i32 0, i32 i32 0.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 15 17:44:48 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGac8c720d4863: [IR] Allow constant folding (insertelement <vscale x 2 x i32> zeroinitializer… (authored by craig.topper).

Changed prior to commit:
  https://reviews.llvm.org/D123413?vs=421632&id=423194#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123413

Files:
  llvm/lib/IR/ConstantFold.cpp
  llvm/test/Transforms/InstSimplify/ConstProp/InsertElement.ll
  llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-phi.ll


Index: llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-phi.ll
===================================================================
--- llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-phi.ll
+++ llvm/test/Transforms/LoopVectorize/AArch64/sve-widen-phi.ll
@@ -251,7 +251,7 @@
 ; CHECK:       vector.body:
 ; CHECK-NEXT:    [[POINTER_PHI:%.*]] = phi i32* [ [[A]], [[VECTOR_PH]] ], [ [[PTR_IND:%.*]], [[VECTOR_BODY]] ]
 ; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
-; CHECK-NEXT:    [[VEC_PHI:%.*]] = phi <vscale x 2 x i32> [ insertelement (<vscale x 2 x i32> zeroinitializer, i32 0, i32 0), [[VECTOR_PH]] ], [ [[TMP9:%.*]], [[VECTOR_BODY]] ]
+; CHECK-NEXT:    [[VEC_PHI:%.*]] = phi <vscale x 2 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP9:%.*]], [[VECTOR_BODY]] ]
 ; CHECK-NEXT:    [[TMP4:%.*]] = call i64 @llvm.vscale.i64()
 ; CHECK-NEXT:    [[TMP5:%.*]] = shl nuw nsw i64 [[TMP4]], 1
 ; CHECK-NEXT:    [[TMP6:%.*]] = call <vscale x 2 x i64> @llvm.experimental.stepvector.nxv2i64()
Index: llvm/test/Transforms/InstSimplify/ConstProp/InsertElement.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/ConstProp/InsertElement.ll
+++ llvm/test/Transforms/InstSimplify/ConstProp/InsertElement.ll
@@ -50,3 +50,19 @@
   %E = extractelement <2 x i64> <i64 -1, i64 -1>, i64 undef
   ret i64 %E
 }
+
+define <vscale x 2 x i32> @insertelement_scalable_null() {
+; CHECK-LABEL: @insertelement_scalable_null(
+; CHECK-NEXT:    ret <vscale x 2 x i32> zeroinitializer
+;
+  %vec = insertelement <vscale x 2 x i32> zeroinitializer, i32 0, i32 0
+  ret <vscale x 2 x i32> %vec
+}
+
+define <vscale x 2 x float> @insertelement_scalable_null_fp() {
+; CHECK-LABEL: @insertelement_scalable_null_fp(
+; CHECK-NEXT:    ret <vscale x 2 x float> zeroinitializer
+;
+  %vec = insertelement <vscale x 2 x float> zeroinitializer, float 0.0, i32 1
+  ret <vscale x 2 x float> %vec
+}
Index: llvm/lib/IR/ConstantFold.cpp
===================================================================
--- llvm/lib/IR/ConstantFold.cpp
+++ llvm/lib/IR/ConstantFold.cpp
@@ -683,6 +683,11 @@
   if (isa<UndefValue>(Idx))
     return PoisonValue::get(Val->getType());
 
+  // Inserting null into all zeros is still all zeros.
+  // TODO: This is true for undef and poison splats too.
+  if (isa<ConstantAggregateZero>(Val) && Elt->isNullValue())
+    return Val;
+
   ConstantInt *CIdx = dyn_cast<ConstantInt>(Idx);
   if (!CIdx) return nullptr;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123413.423194.patch
Type: text/x-patch
Size: 2531 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220416/30d64eeb/attachment.bin>


More information about the llvm-commits mailing list