[llvm] f412b78 - [InstCombine] Return poison if all lanes are poison

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 19 03:43:31 PST 2023


Author: Nikita Popov
Date: 2023-12-19T12:43:23+01:00
New Revision: f412b78ffc2b88b614a10310ca9ba473f1f0f9b9

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

LOG: [InstCombine] Return poison if all lanes are poison

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
    llvm/test/Transforms/InstCombine/X86/x86-pack-inseltpoison.ll
    llvm/test/Transforms/InstCombine/X86/x86-pshufb-inseltpoison.ll
    llvm/test/Transforms/InstCombine/X86/x86-sse4a-inseltpoison.ll
    llvm/test/Transforms/InstCombine/X86/x86-sse4a.ll
    llvm/test/Transforms/InstCombine/vec_demanded_elts-inseltpoison.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
index 48b97ca4696680..a8a5f9831e15e3 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -1867,10 +1867,10 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
     PoisonElts &= PoisonElts2;
   }
 
-  // If we've proven all of the lanes undef, return an undef value.
+  // If we've proven all of the lanes poison, return a poison value.
   // TODO: Intersect w/demanded lanes
   if (PoisonElts.isAllOnes())
-    return UndefValue::get(I->getType());
+    return PoisonValue::get(I->getType());
 
   return MadeChange ? I : nullptr;
 }

diff  --git a/llvm/test/Transforms/InstCombine/X86/x86-pack-inseltpoison.ll b/llvm/test/Transforms/InstCombine/X86/x86-pack-inseltpoison.ll
index 9c85ca504becac..74d58bae742746 100644
--- a/llvm/test/Transforms/InstCombine/X86/x86-pack-inseltpoison.ll
+++ b/llvm/test/Transforms/InstCombine/X86/x86-pack-inseltpoison.ll
@@ -7,7 +7,7 @@
 
 define <8 x i16> @poison_packssdw_128() {
 ; CHECK-LABEL: @poison_packssdw_128(
-; CHECK-NEXT:    ret <8 x i16> undef
+; CHECK-NEXT:    ret <8 x i16> poison
 ;
   %1 = call <8 x i16> @llvm.x86.sse2.packssdw.128(<4 x i32> poison, <4 x i32> poison)
   ret <8 x i16> %1
@@ -15,7 +15,7 @@ define <8 x i16> @poison_packssdw_128() {
 
 define <8 x i16> @poison_packusdw_128() {
 ; CHECK-LABEL: @poison_packusdw_128(
-; CHECK-NEXT:    ret <8 x i16> undef
+; CHECK-NEXT:    ret <8 x i16> poison
 ;
   %1 = call <8 x i16> @llvm.x86.sse41.packusdw(<4 x i32> poison, <4 x i32> poison)
   ret <8 x i16> %1
@@ -23,7 +23,7 @@ define <8 x i16> @poison_packusdw_128() {
 
 define <16 x i8> @poison_packsswb_128() {
 ; CHECK-LABEL: @poison_packsswb_128(
-; CHECK-NEXT:    ret <16 x i8> undef
+; CHECK-NEXT:    ret <16 x i8> poison
 ;
   %1 = call <16 x i8> @llvm.x86.sse2.packsswb.128(<8 x i16> poison, <8 x i16> poison)
   ret <16 x i8> %1
@@ -31,7 +31,7 @@ define <16 x i8> @poison_packsswb_128() {
 
 define <16 x i8> @poison_packuswb_128() {
 ; CHECK-LABEL: @poison_packuswb_128(
-; CHECK-NEXT:    ret <16 x i8> undef
+; CHECK-NEXT:    ret <16 x i8> poison
 ;
   %1 = call <16 x i8> @llvm.x86.sse2.packuswb.128(<8 x i16> poison, <8 x i16> poison)
   ret <16 x i8> %1
@@ -39,7 +39,7 @@ define <16 x i8> @poison_packuswb_128() {
 
 define <16 x i16> @poison_packssdw_256() {
 ; CHECK-LABEL: @poison_packssdw_256(
-; CHECK-NEXT:    ret <16 x i16> undef
+; CHECK-NEXT:    ret <16 x i16> poison
 ;
   %1 = call <16 x i16> @llvm.x86.avx2.packssdw(<8 x i32> poison, <8 x i32> poison)
   ret <16 x i16> %1
@@ -47,7 +47,7 @@ define <16 x i16> @poison_packssdw_256() {
 
 define <16 x i16> @poison_packusdw_256() {
 ; CHECK-LABEL: @poison_packusdw_256(
-; CHECK-NEXT:    ret <16 x i16> undef
+; CHECK-NEXT:    ret <16 x i16> poison
 ;
   %1 = call <16 x i16> @llvm.x86.avx2.packusdw(<8 x i32> poison, <8 x i32> poison)
   ret <16 x i16> %1
@@ -55,7 +55,7 @@ define <16 x i16> @poison_packusdw_256() {
 
 define <32 x i8> @poison_packsswb_256() {
 ; CHECK-LABEL: @poison_packsswb_256(
-; CHECK-NEXT:    ret <32 x i8> undef
+; CHECK-NEXT:    ret <32 x i8> poison
 ;
   %1 = call <32 x i8> @llvm.x86.avx2.packsswb(<16 x i16> poison, <16 x i16> poison)
   ret <32 x i8> %1
@@ -63,7 +63,7 @@ define <32 x i8> @poison_packsswb_256() {
 
 define <32 x i8> @poison_packuswb_256() {
 ; CHECK-LABEL: @poison_packuswb_256(
-; CHECK-NEXT:    ret <32 x i8> undef
+; CHECK-NEXT:    ret <32 x i8> poison
 ;
   %1 = call <32 x i8> @llvm.x86.avx2.packuswb(<16 x i16> poison, <16 x i16> poison)
   ret <32 x i8> %1
@@ -71,7 +71,7 @@ define <32 x i8> @poison_packuswb_256() {
 
 define <32 x i16> @poison_packssdw_512() {
 ; CHECK-LABEL: @poison_packssdw_512(
-; CHECK-NEXT:    ret <32 x i16> undef
+; CHECK-NEXT:    ret <32 x i16> poison
 ;
   %1 = call <32 x i16> @llvm.x86.avx512.packssdw.512(<16 x i32> poison, <16 x i32> poison)
   ret <32 x i16> %1
@@ -79,7 +79,7 @@ define <32 x i16> @poison_packssdw_512() {
 
 define <32 x i16> @poison_packusdw_512() {
 ; CHECK-LABEL: @poison_packusdw_512(
-; CHECK-NEXT:    ret <32 x i16> undef
+; CHECK-NEXT:    ret <32 x i16> poison
 ;
   %1 = call <32 x i16> @llvm.x86.avx512.packusdw.512(<16 x i32> poison, <16 x i32> poison)
   ret <32 x i16> %1
@@ -87,7 +87,7 @@ define <32 x i16> @poison_packusdw_512() {
 
 define <64 x i8> @poison_packsswb_512() {
 ; CHECK-LABEL: @poison_packsswb_512(
-; CHECK-NEXT:    ret <64 x i8> undef
+; CHECK-NEXT:    ret <64 x i8> poison
 ;
   %1 = call <64 x i8> @llvm.x86.avx512.packsswb.512(<32 x i16> poison, <32 x i16> poison)
   ret <64 x i8> %1
@@ -95,7 +95,7 @@ define <64 x i8> @poison_packsswb_512() {
 
 define <64 x i8> @poison_packuswb_512() {
 ; CHECK-LABEL: @poison_packuswb_512(
-; CHECK-NEXT:    ret <64 x i8> undef
+; CHECK-NEXT:    ret <64 x i8> poison
 ;
   %1 = call <64 x i8> @llvm.x86.avx512.packuswb.512(<32 x i16> poison, <32 x i16> poison)
   ret <64 x i8> %1

diff  --git a/llvm/test/Transforms/InstCombine/X86/x86-pshufb-inseltpoison.ll b/llvm/test/Transforms/InstCombine/X86/x86-pshufb-inseltpoison.ll
index c98f1c7b5c8393..2f301e9e9c1072 100644
--- a/llvm/test/Transforms/InstCombine/X86/x86-pshufb-inseltpoison.ll
+++ b/llvm/test/Transforms/InstCombine/X86/x86-pshufb-inseltpoison.ll
@@ -446,7 +446,7 @@ define <64 x i8> @fold_with_poison_elts_avx512(<64 x i8> %InVec) {
 
 define <16 x i8> @fold_with_allpoison_elts(<16 x i8> %InVec) {
 ; CHECK-LABEL: @fold_with_allpoison_elts(
-; CHECK-NEXT:    ret <16 x i8> undef
+; CHECK-NEXT:    ret <16 x i8> poison
 ;
   %1 = tail call <16 x i8> @llvm.x86.ssse3.pshuf.b.128(<16 x i8> %InVec, <16 x i8> poison)
   ret <16 x i8> %1
@@ -454,7 +454,7 @@ define <16 x i8> @fold_with_allpoison_elts(<16 x i8> %InVec) {
 
 define <32 x i8> @fold_with_allpoison_elts_avx2(<32 x i8> %InVec) {
 ; CHECK-LABEL: @fold_with_allpoison_elts_avx2(
-; CHECK-NEXT:    ret <32 x i8> undef
+; CHECK-NEXT:    ret <32 x i8> poison
 ;
   %1 = tail call <32 x i8> @llvm.x86.avx2.pshuf.b(<32 x i8> %InVec, <32 x i8> poison)
   ret <32 x i8> %1
@@ -462,7 +462,7 @@ define <32 x i8> @fold_with_allpoison_elts_avx2(<32 x i8> %InVec) {
 
 define <64 x i8> @fold_with_allpoison_elts_avx512(<64 x i8> %InVec) {
 ; CHECK-LABEL: @fold_with_allpoison_elts_avx512(
-; CHECK-NEXT:    ret <64 x i8> undef
+; CHECK-NEXT:    ret <64 x i8> poison
 ;
   %1 = tail call <64 x i8> @llvm.x86.avx512.pshuf.b.512(<64 x i8> %InVec, <64 x i8> poison)
   ret <64 x i8> %1

diff  --git a/llvm/test/Transforms/InstCombine/X86/x86-sse4a-inseltpoison.ll b/llvm/test/Transforms/InstCombine/X86/x86-sse4a-inseltpoison.ll
index 14630e8031706f..7462e311b02ad2 100644
--- a/llvm/test/Transforms/InstCombine/X86/x86-sse4a-inseltpoison.ll
+++ b/llvm/test/Transforms/InstCombine/X86/x86-sse4a-inseltpoison.ll
@@ -322,7 +322,7 @@ define <2 x i64> @test_extrq_args01(<2 x i64> %x, <16 x i8> %y) {
 
 define <2 x i64> @test_extrq_ret(<2 x i64> %x, <16 x i8> %y) {
 ; CHECK-LABEL: @test_extrq_ret(
-; CHECK-NEXT:    ret <2 x i64> undef
+; CHECK-NEXT:    ret <2 x i64> poison
 ;
   %1 = tail call <2 x i64> @llvm.x86.sse4a.extrq(<2 x i64> %x, <16 x i8> %y) nounwind
   %2 = shufflevector <2 x i64> %1, <2 x i64> poison, <2 x i32> <i32 1, i32 1>
@@ -341,7 +341,7 @@ define <2 x i64> @test_extrqi_arg0(<2 x i64> %x) {
 
 define <2 x i64> @test_extrqi_ret(<2 x i64> %x) {
 ; CHECK-LABEL: @test_extrqi_ret(
-; CHECK-NEXT:    ret <2 x i64> undef
+; CHECK-NEXT:    ret <2 x i64> poison
 ;
   %1 = tail call <2 x i64> @llvm.x86.sse4a.extrqi(<2 x i64> %x, i8 3, i8 2) nounwind
   %2 = shufflevector <2 x i64> %1, <2 x i64> poison, <2 x i32> <i32 1, i32 1>
@@ -360,7 +360,7 @@ define <2 x i64> @test_insertq_arg0(<2 x i64> %x, <2 x i64> %y) {
 
 define <2 x i64> @test_insertq_ret(<2 x i64> %x, <2 x i64> %y) {
 ; CHECK-LABEL: @test_insertq_ret(
-; CHECK-NEXT:    ret <2 x i64> undef
+; CHECK-NEXT:    ret <2 x i64> poison
 ;
   %1 = tail call <2 x i64> @llvm.x86.sse4a.insertq(<2 x i64> %x, <2 x i64> %y) nounwind
   %2 = shufflevector <2 x i64> %1, <2 x i64> poison, <2 x i32> <i32 1, i32 1>
@@ -400,7 +400,7 @@ define <2 x i64> @test_insertqi_args01(<2 x i64> %x, <2 x i64> %y) {
 
 define <2 x i64> @test_insertqi_ret(<2 x i64> %x, <2 x i64> %y) {
 ; CHECK-LABEL: @test_insertqi_ret(
-; CHECK-NEXT:    ret <2 x i64> undef
+; CHECK-NEXT:    ret <2 x i64> poison
 ;
   %1 = tail call <2 x i64> @llvm.x86.sse4a.insertqi(<2 x i64> %x, <2 x i64> %y, i8 3, i8 2) nounwind
   %2 = shufflevector <2 x i64> %1, <2 x i64> poison, <2 x i32> <i32 1, i32 1>

diff  --git a/llvm/test/Transforms/InstCombine/X86/x86-sse4a.ll b/llvm/test/Transforms/InstCombine/X86/x86-sse4a.ll
index 6171b2ee4cf551..6277986288a8c3 100644
--- a/llvm/test/Transforms/InstCombine/X86/x86-sse4a.ll
+++ b/llvm/test/Transforms/InstCombine/X86/x86-sse4a.ll
@@ -322,7 +322,7 @@ define <2 x i64> @test_extrq_args01(<2 x i64> %x, <16 x i8> %y) {
 
 define <2 x i64> @test_extrq_ret(<2 x i64> %x, <16 x i8> %y) {
 ; CHECK-LABEL: @test_extrq_ret(
-; CHECK-NEXT:    ret <2 x i64> undef
+; CHECK-NEXT:    ret <2 x i64> poison
 ;
   %1 = tail call <2 x i64> @llvm.x86.sse4a.extrq(<2 x i64> %x, <16 x i8> %y) nounwind
   %2 = shufflevector <2 x i64> %1, <2 x i64> undef, <2 x i32> <i32 1, i32 1>
@@ -341,7 +341,7 @@ define <2 x i64> @test_extrqi_arg0(<2 x i64> %x) {
 
 define <2 x i64> @test_extrqi_ret(<2 x i64> %x) {
 ; CHECK-LABEL: @test_extrqi_ret(
-; CHECK-NEXT:    ret <2 x i64> undef
+; CHECK-NEXT:    ret <2 x i64> poison
 ;
   %1 = tail call <2 x i64> @llvm.x86.sse4a.extrqi(<2 x i64> %x, i8 3, i8 2) nounwind
   %2 = shufflevector <2 x i64> %1, <2 x i64> undef, <2 x i32> <i32 1, i32 1>
@@ -360,7 +360,7 @@ define <2 x i64> @test_insertq_arg0(<2 x i64> %x, <2 x i64> %y) {
 
 define <2 x i64> @test_insertq_ret(<2 x i64> %x, <2 x i64> %y) {
 ; CHECK-LABEL: @test_insertq_ret(
-; CHECK-NEXT:    ret <2 x i64> undef
+; CHECK-NEXT:    ret <2 x i64> poison
 ;
   %1 = tail call <2 x i64> @llvm.x86.sse4a.insertq(<2 x i64> %x, <2 x i64> %y) nounwind
   %2 = shufflevector <2 x i64> %1, <2 x i64> undef, <2 x i32> <i32 1, i32 1>
@@ -400,7 +400,7 @@ define <2 x i64> @test_insertqi_args01(<2 x i64> %x, <2 x i64> %y) {
 
 define <2 x i64> @test_insertqi_ret(<2 x i64> %x, <2 x i64> %y) {
 ; CHECK-LABEL: @test_insertqi_ret(
-; CHECK-NEXT:    ret <2 x i64> undef
+; CHECK-NEXT:    ret <2 x i64> poison
 ;
   %1 = tail call <2 x i64> @llvm.x86.sse4a.insertqi(<2 x i64> %x, <2 x i64> %y, i8 3, i8 2) nounwind
   %2 = shufflevector <2 x i64> %1, <2 x i64> undef, <2 x i32> <i32 1, i32 1>

diff  --git a/llvm/test/Transforms/InstCombine/vec_demanded_elts-inseltpoison.ll b/llvm/test/Transforms/InstCombine/vec_demanded_elts-inseltpoison.ll
index 1a1d5a892daae7..25f5c39c2c9484 100644
--- a/llvm/test/Transforms/InstCombine/vec_demanded_elts-inseltpoison.ll
+++ b/llvm/test/Transforms/InstCombine/vec_demanded_elts-inseltpoison.ll
@@ -145,7 +145,7 @@ define <2 x i64> @PR24922(<2 x i64> %v) {
 
 define <4 x float> @inselt_shuf_no_demand(float %a1, float %a2, float %a3) {
 ; CHECK-LABEL: @inselt_shuf_no_demand(
-; CHECK-NEXT:    ret <4 x float> undef
+; CHECK-NEXT:    ret <4 x float> poison
 ;
   %out1 = insertelement <4 x float> poison, float %a1, i32 1
   %out12 = insertelement <4 x float> %out1, float %a2, i32 2
@@ -158,7 +158,7 @@ define <4 x float> @inselt_shuf_no_demand(float %a1, float %a2, float %a3) {
 
 define <4 x float> @inselt_shuf_no_demand_commute(float %a1, float %a2, float %a3) {
 ; CHECK-LABEL: @inselt_shuf_no_demand_commute(
-; CHECK-NEXT:    ret <4 x float> undef
+; CHECK-NEXT:    ret <4 x float> poison
 ;
   %out1 = insertelement <4 x float> poison, float %a1, i32 1
   %out12 = insertelement <4 x float> %out1, float %a2, i32 2
@@ -627,7 +627,7 @@ define <2 x ptr> @gep_all_lanes_undef(ptr %base, i64 %idx) {;
 
 define ptr @gep_demanded_lane_undef(ptr %base, i64 %idx) {
 ; CHECK-LABEL: @gep_demanded_lane_undef(
-; CHECK-NEXT:    ret ptr undef
+; CHECK-NEXT:    ret ptr poison
 ;
   %basevec = insertelement <2 x ptr> poison, ptr %base, i32 0
   %idxvec = insertelement <2 x i64> poison, i64 %idx, i32 1


        


More information about the llvm-commits mailing list