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

Juneyoung Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 4 17:20:17 PST 2021


aqjune updated this revision to Diff 314485.
aqjune added a comment.

Address comment


Repository:
  rG LLVM Github Monorepo

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

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) && isGuaranteedNotToBePoison(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.314485.patch
Type: text/x-patch
Size: 1435 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210105/eb867f5f/attachment.bin>


More information about the llvm-commits mailing list