[PATCH] D93994: [InstSimplify] Fold insertelement vec, poison, idx into vec

Juneyoung Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 3 09:05:22 PST 2021


aqjune created this revision.
aqjune added a reviewer: nikic.
Herald added a subscriber: hiraditya.
aqjune requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This is a simple patch that adds folding from `insertelement vec, poison, idx` into `vec`.

Alive2 proof: https://alive2.llvm.org/ce/z/2y2vbC


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93994

Files:
  llvm/lib/Analysis/InstructionSimplify.cpp
  llvm/test/Transforms/InstSimplify/insertelement.ll


Index: llvm/test/Transforms/InstSimplify/insertelement.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/insertelement.ll
+++ llvm/test/Transforms/InstSimplify/insertelement.ll
@@ -52,8 +52,7 @@
 
 define <4 x i32> @elem_poison(<4 x i32> %A) {
 ; CHECK-LABEL: @elem_poison(
-; CHECK-NEXT:    [[B:%.*]] = insertelement <4 x i32> [[A:%.*]], i32 poison, i32 1
-; CHECK-NEXT:    ret <4 x i32> [[B]]
+; CHECK-NEXT:    ret <4 x i32> [[A:%.*]]
 ;
   %B = insertelement <4 x i32> %A, i32 poison, i32 1
   ret <4 x i32> %B
Index: llvm/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/lib/Analysis/InstructionSimplify.cpp
+++ llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4396,10 +4396,10 @@
   if (Q.isUndefValue(Idx))
     return PoisonValue::get(Vec->getType());
 
-  // If the scalar is undef, and there is no risk of propagating poison from the
-  // vector value, simplify to the vector value.
-  if (Q.isUndefValue(Val) &&
-      isGuaranteedNotToBeUndefOrPoison(Vec))
+  // If the scalar is poison, or it is undef and there is no risk of
+  // propagating poison from the vector value, simplify to the vector value.
+  if (isa<PoisonValue>(Val) ||
+      (Q.isUndefValue(Val) && isGuaranteedNotToBeUndefOrPoison(Vec)))
     return Vec;
 
   // If we are extracting a value from a vector, then inserting it into the same


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93994.314290.patch
Type: text/x-patch
Size: 1442 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210103/124dcad3/attachment.bin>


More information about the llvm-commits mailing list