[llvm] 853d212 - [InstSimplify] Update to handle new shufflevector semantics

via llvm-commits llvm-commits at lists.llvm.org
Wed May 3 13:31:56 PDT 2023


Author: ManuelJBrito
Date: 2023-05-03T21:31:19+01:00
New Revision: 853d212e323abd471b09adfe06f3391eda2526f9

URL: https://github.com/llvm/llvm-project/commit/853d212e323abd471b09adfe06f3391eda2526f9
DIFF: https://github.com/llvm/llvm-project/commit/853d212e323abd471b09adfe06f3391eda2526f9.diff

LOG: [InstSimplify] Update to handle new shufflevector semantics

Simplifying poison mask elements yields poison values.

Differential Revision: https://reviews.llvm.org/D149544

Added: 
    

Modified: 
    llvm/lib/Analysis/InstructionSimplify.cpp
    llvm/test/Transforms/InstSimplify/shufflevector-inseltpoison.ll
    llvm/test/Transforms/InstSimplify/shufflevector.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 5b3543a8856f1..75fa94fb02165 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -5236,7 +5236,7 @@ static Value *simplifyShuffleVectorInst(Value *Op0, Value *Op1,
                                         const SimplifyQuery &Q,
                                         unsigned MaxRecurse) {
   if (all_of(Mask, [](int Elem) { return Elem == PoisonMaskElem; }))
-    return UndefValue::get(RetTy);
+    return PoisonValue::get(RetTy);
 
   auto *InVecTy = cast<VectorType>(Op0->getType());
   unsigned MaskNumElts = Mask.size();
@@ -5301,11 +5301,11 @@ static Value *simplifyShuffleVectorInst(Value *Op0, Value *Op1,
         })) {
       assert(isa<UndefValue>(Op1) && "Expected undef operand 1 for splat");
 
-      // Shuffle mask undefs become undefined constant result elements.
+      // Shuffle mask poisons become poison constant result elements.
       SmallVector<Constant *, 16> VecC(MaskNumElts, C);
       for (unsigned i = 0; i != MaskNumElts; ++i)
         if (Indices[i] == -1)
-          VecC[i] = UndefValue::get(C->getType());
+          VecC[i] = PoisonValue::get(C->getType());
       return ConstantVector::get(VecC);
     }
   }

diff  --git a/llvm/test/Transforms/InstSimplify/shufflevector-inseltpoison.ll b/llvm/test/Transforms/InstSimplify/shufflevector-inseltpoison.ll
index 427171e3988ab..49cacdc1e8d0f 100644
--- a/llvm/test/Transforms/InstSimplify/shufflevector-inseltpoison.ll
+++ b/llvm/test/Transforms/InstSimplify/shufflevector-inseltpoison.ll
@@ -122,7 +122,7 @@ define <4 x i32> @splat_operand_negative4(<4 x i32> %x) {
 
 define <4 x i32> @undef_mask(<4 x i32> %x) {
 ; CHECK-LABEL: @undef_mask(
-; CHECK-NEXT:    ret <4 x i32> undef
+; CHECK-NEXT:    ret <4 x i32> poison
 ;
   %shuf = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> poison
   ret <4 x i32> %shuf
@@ -130,7 +130,7 @@ define <4 x i32> @undef_mask(<4 x i32> %x) {
 
 define <4 x i32> @undef_mask_1(<4 x i32> %x, <4 x i32> %y) {
 ; CHECK-LABEL: @undef_mask_1(
-; CHECK-NEXT:    ret <4 x i32> undef
+; CHECK-NEXT:    ret <4 x i32> poison
 ;
   %shuf = shufflevector <4 x i32> %x, <4 x i32> %y, <4 x i32> poison
   ret <4 x i32> %shuf
@@ -269,7 +269,7 @@ define <5 x i8> @splat_inserted_constant(<4 x i8> %x) {
 
 define <4 x float> @splat_inserted_constant_undef_elt(<4 x float> %x) {
 ; CHECK-LABEL: @splat_inserted_constant_undef_elt(
-; CHECK-NEXT:    ret <4 x float> <float 1.200000e+01, float 1.200000e+01, float undef, float 1.200000e+01>
+; CHECK-NEXT:    ret <4 x float> <float 1.200000e+01, float 1.200000e+01, float poison, float 1.200000e+01>
 ;
   %ins1 = insertelement <4 x float> %x, float 12.0, i32 1
   %splat1 = shufflevector <4 x float> %ins1, <4 x float> poison, <4 x i32> <i32 1, i32 1, i32 undef, i32 1>
@@ -278,7 +278,7 @@ define <4 x float> @splat_inserted_constant_undef_elt(<4 x float> %x) {
 
 define <2 x i8> @splat_inserted_constant_not_canonical(<3 x i8> %x, <3 x i8> %y) {
 ; CHECK-LABEL: @splat_inserted_constant_not_canonical(
-; CHECK-NEXT:    ret <2 x i8> <i8 undef, i8 23>
+; CHECK-NEXT:    ret <2 x i8> <i8 poison, i8 23>
 ;
   %ins2 = insertelement <3 x i8> %x, i8 23, i7 2
   %splat2 = shufflevector <3 x i8> %y, <3 x i8> %ins2, <2 x i32> <i32 undef, i32 5>

diff  --git a/llvm/test/Transforms/InstSimplify/shufflevector.ll b/llvm/test/Transforms/InstSimplify/shufflevector.ll
index ff1a80f40a969..460e90aa31d91 100644
--- a/llvm/test/Transforms/InstSimplify/shufflevector.ll
+++ b/llvm/test/Transforms/InstSimplify/shufflevector.ll
@@ -122,7 +122,7 @@ define <4 x i32> @splat_operand_negative4(<4 x i32> %x) {
 
 define <4 x i32> @undef_mask(<4 x i32> %x) {
 ; CHECK-LABEL: @undef_mask(
-; CHECK-NEXT:    ret <4 x i32> undef
+; CHECK-NEXT:    ret <4 x i32> poison
 ;
   %shuf = shufflevector <4 x i32> %x, <4 x i32> undef, <4 x i32> undef
   ret <4 x i32> %shuf
@@ -130,7 +130,7 @@ define <4 x i32> @undef_mask(<4 x i32> %x) {
 
 define <4 x i32> @undef_mask_1(<4 x i32> %x, <4 x i32> %y) {
 ; CHECK-LABEL: @undef_mask_1(
-; CHECK-NEXT:    ret <4 x i32> undef
+; CHECK-NEXT:    ret <4 x i32> poison
 ;
   %shuf = shufflevector <4 x i32> %x, <4 x i32> %y, <4 x i32> undef
   ret <4 x i32> %shuf
@@ -269,7 +269,7 @@ define <5 x i8> @splat_inserted_constant(<4 x i8> %x) {
 
 define <4 x float> @splat_inserted_constant_undef_elt(<4 x float> %x) {
 ; CHECK-LABEL: @splat_inserted_constant_undef_elt(
-; CHECK-NEXT:    ret <4 x float> <float 1.200000e+01, float 1.200000e+01, float undef, float 1.200000e+01>
+; CHECK-NEXT:    ret <4 x float> <float 1.200000e+01, float 1.200000e+01, float poison, float 1.200000e+01>
 ;
   %ins1 = insertelement <4 x float> %x, float 12.0, i32 1
   %splat1 = shufflevector <4 x float> %ins1, <4 x float> undef, <4 x i32> <i32 1, i32 1, i32 undef, i32 1>
@@ -278,7 +278,7 @@ define <4 x float> @splat_inserted_constant_undef_elt(<4 x float> %x) {
 
 define <2 x i8> @splat_inserted_constant_not_canonical(<3 x i8> %x, <3 x i8> %y) {
 ; CHECK-LABEL: @splat_inserted_constant_not_canonical(
-; CHECK-NEXT:    ret <2 x i8> <i8 undef, i8 23>
+; CHECK-NEXT:    ret <2 x i8> <i8 poison, i8 23>
 ;
   %ins2 = insertelement <3 x i8> %x, i8 23, i7 2
   %splat2 = shufflevector <3 x i8> %y, <3 x i8> %ins2, <2 x i32> <i32 undef, i32 5>


        


More information about the llvm-commits mailing list