[llvm-branch-commits] [llvm] 766cf7f - [InstSimplify] Fold division by zero to poison

Nikita Popov via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Jan 3 11:58:04 PST 2021


Author: Nikita Popov
Date: 2021-01-03T20:52:45+01:00
New Revision: 766cf7f32e4f0974dbccd9771317a102533aa0df

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

LOG: [InstSimplify] Fold division by zero to poison

Div/rem by zero is immediate undefined behavior and anything goes.
Currently we fold it to undef, this patch changes it to fold to
poison instead, which is slightly stronger.

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

Added: 
    

Modified: 
    llvm/lib/Analysis/InstructionSimplify.cpp
    llvm/test/Transforms/InstCombine/add-shl-sdiv-to-srem.ll
    llvm/test/Transforms/InstCombine/div.ll
    llvm/test/Transforms/InstCombine/icmp-div-constant.ll
    llvm/test/Transforms/InstCombine/inselt-binop-inseltpoison.ll
    llvm/test/Transforms/InstCombine/inselt-binop.ll
    llvm/test/Transforms/InstCombine/rem.ll
    llvm/test/Transforms/InstCombine/sdiv-exact-by-negative-power-of-two.ll
    llvm/test/Transforms/InstCombine/sdiv-exact-by-power-of-two.ll
    llvm/test/Transforms/InstCombine/shift.ll
    llvm/test/Transforms/InstCombine/vector-udiv.ll
    llvm/test/Transforms/InstCombine/vector-urem.ll
    llvm/test/Transforms/InstSimplify/div.ll
    llvm/test/Transforms/InstSimplify/rem.ll
    llvm/test/Transforms/InstSimplify/undef.ll
    llvm/test/Transforms/SLPVectorizer/X86/alternate-int-inseltpoison.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 4706969eafc0..0655374cbc1d 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -924,19 +924,19 @@ static Value *simplifyDivRem(Value *Op0, Value *Op1, bool IsDiv,
                              const SimplifyQuery &Q) {
   Type *Ty = Op0->getType();
 
-  // X / undef -> undef
-  // X % undef -> undef
+  // X / undef -> poison
+  // X % undef -> poison
   if (Q.isUndefValue(Op1))
-    return Op1;
+    return PoisonValue::get(Ty);
 
-  // X / 0 -> undef
-  // X % 0 -> undef
+  // X / 0 -> poison
+  // X % 0 -> poison
   // We don't need to preserve faults!
   if (match(Op1, m_Zero()))
-    return UndefValue::get(Ty);
+    return PoisonValue::get(Ty);
 
-  // If any element of a constant divisor fixed width vector is zero or undef,
-  // the whole op is undef.
+  // If any element of a constant divisor fixed width vector is zero or undef
+  // the behavior is undefined and we can fold the whole op to poison.
   auto *Op1C = dyn_cast<Constant>(Op1);
   auto *VTy = dyn_cast<FixedVectorType>(Ty);
   if (Op1C && VTy) {
@@ -944,7 +944,7 @@ static Value *simplifyDivRem(Value *Op0, Value *Op1, bool IsDiv,
     for (unsigned i = 0; i != NumElts; ++i) {
       Constant *Elt = Op1C->getAggregateElement(i);
       if (Elt && (Elt->isNullValue() || Q.isUndefValue(Elt)))
-        return UndefValue::get(Ty);
+        return PoisonValue::get(Ty);
     }
   }
 

diff  --git a/llvm/test/Transforms/InstCombine/add-shl-sdiv-to-srem.ll b/llvm/test/Transforms/InstCombine/add-shl-sdiv-to-srem.ll
index 57a10c165f15..1dee5eb90ea1 100644
--- a/llvm/test/Transforms/InstCombine/add-shl-sdiv-to-srem.ll
+++ b/llvm/test/Transforms/InstCombine/add-shl-sdiv-to-srem.ll
@@ -212,7 +212,7 @@ define <2 x i64> @add-shl-sdiv-negative4(<2 x i64> %x) {
 
 define <3 x i8> @add-shl-sdiv-3xi8-undef0(<3 x i8> %x) {
 ; CHECK-LABEL: @add-shl-sdiv-3xi8-undef0(
-; CHECK-NEXT:    ret <3 x i8> [[X:%.*]]
+; CHECK-NEXT:    ret <3 x i8> poison
 ;
   %sd = sdiv <3 x i8> %x, <i8 -4, i8 undef, i8 -4>
   %sl = shl <3 x i8> %sd, <i8 2, i8 2, i8 2>

diff  --git a/llvm/test/Transforms/InstCombine/div.ll b/llvm/test/Transforms/InstCombine/div.ll
index e06faf43348b..835db5e2c6ca 100644
--- a/llvm/test/Transforms/InstCombine/div.ll
+++ b/llvm/test/Transforms/InstCombine/div.ll
@@ -40,7 +40,7 @@ define <2 x i64> @sdiv_by_minus1_vec(<2 x i64> %x) {
 
 define <2 x i64> @sdiv_by_minus1_vec_undef_elt(<2 x i64> %x) {
 ; CHECK-LABEL: @sdiv_by_minus1_vec_undef_elt(
-; CHECK-NEXT:    ret <2 x i64> undef
+; CHECK-NEXT:    ret <2 x i64> poison
 ;
   %div = sdiv <2 x i64> %x, <i64 -1, i64 undef>
   ret <2 x i64> %div
@@ -514,7 +514,7 @@ define <2 x i8> @sdiv_negated_dividend_constant_divisor_vec_splat_smin(<2 x i8>
 
 define <2 x i8> @sdiv_negated_dividend_constant_divisor_vec_undef(<2 x i8> %x) {
 ; CHECK-LABEL: @sdiv_negated_dividend_constant_divisor_vec_undef(
-; CHECK-NEXT:    ret <2 x i8> undef
+; CHECK-NEXT:    ret <2 x i8> poison
 ;
   %neg = sub nsw <2 x i8> zeroinitializer, %x
   %d = sdiv <2 x i8> %neg, <i8 -128, i8 undef>
@@ -523,8 +523,8 @@ define <2 x i8> @sdiv_negated_dividend_constant_divisor_vec_undef(<2 x i8> %x) {
 
 define <2 x i64> @sdiv_negated_dividend_constant_divisor_vec(<2 x i64> %x) {
 ; CHECK-LABEL: @sdiv_negated_dividend_constant_divisor_vec(
-; CHECK-NEXT:    [[DIV:%.*]] = sdiv <2 x i64> [[X:%.*]], <i64 -3, i64 -4>
-; CHECK-NEXT:    ret <2 x i64> [[DIV]]
+; CHECK-NEXT:    [[DIV1_NEG:%.*]] = sdiv <2 x i64> [[X:%.*]], <i64 -3, i64 -4>
+; CHECK-NEXT:    ret <2 x i64> [[DIV1_NEG]]
 ;
   %neg = sub nsw <2 x i64> zeroinitializer, %x
   %div = sdiv <2 x i64> %neg, <i64 3, i64 4>
@@ -533,8 +533,8 @@ define <2 x i64> @sdiv_negated_dividend_constant_divisor_vec(<2 x i64> %x) {
 
 define <2 x i64> @sdiv_exact_negated_dividend_constant_divisor_vec(<2 x i64> %x) {
 ; CHECK-LABEL: @sdiv_exact_negated_dividend_constant_divisor_vec(
-; CHECK-NEXT:    [[DIV:%.*]] = sdiv exact <2 x i64> [[X:%.*]], <i64 -3, i64 -4>
-; CHECK-NEXT:    ret <2 x i64> [[DIV]]
+; CHECK-NEXT:    [[DIV1_NEG:%.*]] = sdiv exact <2 x i64> [[X:%.*]], <i64 -3, i64 -4>
+; CHECK-NEXT:    ret <2 x i64> [[DIV1_NEG]]
 ;
   %neg = sub nsw <2 x i64> zeroinitializer, %x
   %div = sdiv exact <2 x i64> %neg, <i64 3, i64 4>
@@ -849,8 +849,8 @@ define <2 x i8> @udiv_common_factor_not_nuw_vec(<2 x i8> %x, <2 x i8> %y, <2 x i
 
 define i32 @test_exact_nsw_exact(i32 %x) {
 ; CHECK-LABEL: @test_exact_nsw_exact(
-; CHECK-NEXT:    [[NEG:%.*]] = sdiv exact i32 [[X:%.*]], -3
-; CHECK-NEXT:    ret i32 [[NEG]]
+; CHECK-NEXT:    [[DIV_NEG:%.*]] = sdiv exact i32 [[X:%.*]], -3
+; CHECK-NEXT:    ret i32 [[DIV_NEG]]
 ;
   %div = sdiv exact i32 %x, 3
   %neg = sub nsw i32 0, %div
@@ -859,8 +859,8 @@ define i32 @test_exact_nsw_exact(i32 %x) {
 
 define <2 x i64> @test_exact_vec(<2 x i64> %x) {
 ; CHECK-LABEL: @test_exact_vec(
-; CHECK-NEXT:    [[NEG:%.*]] = sdiv exact <2 x i64> [[X:%.*]], <i64 -3, i64 -4>
-; CHECK-NEXT:    ret <2 x i64> [[NEG]]
+; CHECK-NEXT:    [[DIV_NEG:%.*]] = sdiv exact <2 x i64> [[X:%.*]], <i64 -3, i64 -4>
+; CHECK-NEXT:    ret <2 x i64> [[DIV_NEG]]
 ;
   %div = sdiv exact <2 x i64> %x, <i64 3, i64 4>
   %neg = sub nsw <2 x i64> zeroinitializer, %div
@@ -871,8 +871,8 @@ define <2 x i64> @test_exact_vec(<2 x i64> %x) {
 
 define <2 x i8> @negate_sdiv_vec_splat(<2 x i8> %x) {
 ; CHECK-LABEL: @negate_sdiv_vec_splat(
-; CHECK-NEXT:    [[NEG:%.*]] = sdiv <2 x i8> [[X:%.*]], <i8 -42, i8 -42>
-; CHECK-NEXT:    ret <2 x i8> [[NEG]]
+; CHECK-NEXT:    [[DIV_NEG:%.*]] = sdiv <2 x i8> [[X:%.*]], <i8 -42, i8 -42>
+; CHECK-NEXT:    ret <2 x i8> [[DIV_NEG]]
 ;
   %div = sdiv <2 x i8> %x, <i8 42, i8 42>
   %neg = sub <2 x i8> zeroinitializer, %div
@@ -883,7 +883,7 @@ define <2 x i8> @negate_sdiv_vec_splat(<2 x i8> %x) {
 
 define <2 x i8> @negate_sdiv_vec_undef_elt(<2 x i8> %x) {
 ; CHECK-LABEL: @negate_sdiv_vec_undef_elt(
-; CHECK-NEXT:    ret <2 x i8> undef
+; CHECK-NEXT:    ret <2 x i8> poison
 ;
   %div = sdiv <2 x i8> %x, <i8 undef, i8 42>
   %neg = sub <2 x i8> zeroinitializer, %div
@@ -907,8 +907,8 @@ define <2 x i8> @negate_sdiv_vec_splat_one(<2 x i8> %x) {
 define <2 x i8> @negate_sdiv_vec_splat_signed_min(<2 x i8> %x) {
 ; CHECK-LABEL: @negate_sdiv_vec_splat_signed_min(
 ; CHECK-NEXT:    [[TMP1:%.*]] = icmp eq <2 x i8> [[X:%.*]], <i8 -128, i8 -128>
-; CHECK-NEXT:    [[NEG:%.*]] = sext <2 x i1> [[TMP1]] to <2 x i8>
-; CHECK-NEXT:    ret <2 x i8> [[NEG]]
+; CHECK-NEXT:    [[DIV_NEG:%.*]] = sext <2 x i1> [[TMP1]] to <2 x i8>
+; CHECK-NEXT:    ret <2 x i8> [[DIV_NEG]]
 ;
   %div = sdiv <2 x i8> %x, <i8 -128, i8 -128>
   %neg = sub <2 x i8> zeroinitializer, %div
@@ -956,8 +956,8 @@ define <2 x i8> @negate_sdiv_vec_signed_min_and_one_elt(<2 x i8> %x) {
 
 define i32 @test_exact_nonsw_exact(i32 %x) {
 ; CHECK-LABEL: @test_exact_nonsw_exact(
-; CHECK-NEXT:    [[NEG:%.*]] = sdiv exact i32 [[X:%.*]], -3
-; CHECK-NEXT:    ret i32 [[NEG]]
+; CHECK-NEXT:    [[DIV_NEG:%.*]] = sdiv exact i32 [[X:%.*]], -3
+; CHECK-NEXT:    ret i32 [[DIV_NEG]]
 ;
   %div = sdiv exact i32 %x, 3
   %neg = sub i32 0, %div
@@ -966,8 +966,8 @@ define i32 @test_exact_nonsw_exact(i32 %x) {
 
 define i32 @test_exact_nsw_noexact(i32 %x) {
 ; CHECK-LABEL: @test_exact_nsw_noexact(
-; CHECK-NEXT:    [[NEG:%.*]] = sdiv i32 [[X:%.*]], -3
-; CHECK-NEXT:    ret i32 [[NEG]]
+; CHECK-NEXT:    [[DIV_NEG:%.*]] = sdiv i32 [[X:%.*]], -3
+; CHECK-NEXT:    ret i32 [[DIV_NEG]]
 ;
   %div = sdiv i32 %x, 3
   %neg = sub nsw i32 0, %div
@@ -976,8 +976,8 @@ define i32 @test_exact_nsw_noexact(i32 %x) {
 
 define i32 @test_exact_nonsw_noexact(i32 %x) {
 ; CHECK-LABEL: @test_exact_nonsw_noexact(
-; CHECK-NEXT:    [[NEG:%.*]] = sdiv i32 [[X:%.*]], -3
-; CHECK-NEXT:    ret i32 [[NEG]]
+; CHECK-NEXT:    [[DIV_NEG:%.*]] = sdiv i32 [[X:%.*]], -3
+; CHECK-NEXT:    ret i32 [[DIV_NEG]]
 ;
   %div = sdiv i32 %x, 3
   %neg = sub i32 0, %div
@@ -1008,8 +1008,8 @@ define i32 @test_exact_div_one(i32 %x) {
 define i8 @test_exact_div_minSigned(i8 %x) {
 ; CHECK-LABEL: @test_exact_div_minSigned(
 ; CHECK-NEXT:    [[TMP1:%.*]] = icmp eq i8 [[X:%.*]], -128
-; CHECK-NEXT:    [[NEG:%.*]] = sext i1 [[TMP1]] to i8
-; CHECK-NEXT:    ret i8 [[NEG]]
+; CHECK-NEXT:    [[DIV_NEG:%.*]] = sext i1 [[TMP1]] to i8
+; CHECK-NEXT:    ret i8 [[DIV_NEG]]
 ;
   %div = sdiv exact i8 %x, -128
   %neg = sub nsw i8 0, %div
@@ -1040,7 +1040,7 @@ define <2 x i8> @sdiv_by_int_min_vec_splat(<2 x i8> %x) {
 
 define <2 x i8> @sdiv_by_int_min_vec_splat_undef(<2 x i8> %x) {
 ; CHECK-LABEL: @sdiv_by_int_min_vec_splat_undef(
-; CHECK-NEXT:    ret <2 x i8> undef
+; CHECK-NEXT:    ret <2 x i8> poison
 ;
   %d = sdiv <2 x i8> %x, <i8 -128, i8 undef>
   ret <2 x i8> %d

diff  --git a/llvm/test/Transforms/InstCombine/icmp-div-constant.ll b/llvm/test/Transforms/InstCombine/icmp-div-constant.ll
index b68a5673faa9..64f244f96383 100644
--- a/llvm/test/Transforms/InstCombine/icmp-div-constant.ll
+++ b/llvm/test/Transforms/InstCombine/icmp-div-constant.ll
@@ -119,10 +119,10 @@ define i32 @icmp_div(i16 %a, i16 %c) {
 ; CHECK-NEXT:    br i1 [[TOBOOL]], label [[THEN:%.*]], label [[EXIT:%.*]]
 ; CHECK:       then:
 ; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i16 [[C:%.*]], 0
-; CHECK-NEXT:    [[PHITMP1:%.*]] = sext i1 [[CMP]] to i32
+; CHECK-NEXT:    [[PHI_BO:%.*]] = sext i1 [[CMP]] to i32
 ; CHECK-NEXT:    br label [[EXIT]]
 ; CHECK:       exit:
-; CHECK-NEXT:    [[PHI:%.*]] = phi i32 [ -1, [[ENTRY:%.*]] ], [ [[PHITMP1]], [[THEN]] ]
+; CHECK-NEXT:    [[PHI:%.*]] = phi i32 [ -1, [[ENTRY:%.*]] ], [ [[PHI_BO]], [[THEN]] ]
 ; CHECK-NEXT:    ret i32 [[PHI]]
 ;
 entry:
@@ -149,8 +149,7 @@ define i32 @icmp_div2(i16 %a, i16 %c) {
 ; CHECK:       then:
 ; CHECK-NEXT:    br label [[EXIT]]
 ; CHECK:       exit:
-; CHECK-NEXT:    [[PHI:%.*]] = phi i32 [ -1, [[ENTRY:%.*]] ], [ 0, [[THEN]] ]
-; CHECK-NEXT:    ret i32 [[PHI]]
+; CHECK-NEXT:    ret i32 -1
 ;
 entry:
   %tobool = icmp eq i16 %a, 0
@@ -175,10 +174,10 @@ define i32 @icmp_div3(i16 %a, i16 %c) {
 ; CHECK-NEXT:    br i1 [[TOBOOL]], label [[THEN:%.*]], label [[EXIT:%.*]]
 ; CHECK:       then:
 ; CHECK-NEXT:    [[CMP:%.*]] = icmp eq i16 [[C:%.*]], 0
-; CHECK-NEXT:    [[PHITMP1:%.*]] = sext i1 [[CMP]] to i32
+; CHECK-NEXT:    [[PHI_BO:%.*]] = sext i1 [[CMP]] to i32
 ; CHECK-NEXT:    br label [[EXIT]]
 ; CHECK:       exit:
-; CHECK-NEXT:    [[PHI:%.*]] = phi i32 [ -1, [[ENTRY:%.*]] ], [ [[PHITMP1]], [[THEN]] ]
+; CHECK-NEXT:    [[PHI:%.*]] = phi i32 [ -1, [[ENTRY:%.*]] ], [ [[PHI_BO]], [[THEN]] ]
 ; CHECK-NEXT:    ret i32 [[PHI]]
 ;
 entry:

diff  --git a/llvm/test/Transforms/InstCombine/inselt-binop-inseltpoison.ll b/llvm/test/Transforms/InstCombine/inselt-binop-inseltpoison.ll
index 856eb61ba0ba..adcbc3af3900 100644
--- a/llvm/test/Transforms/InstCombine/inselt-binop-inseltpoison.ll
+++ b/llvm/test/Transforms/InstCombine/inselt-binop-inseltpoison.ll
@@ -247,7 +247,7 @@ define <2 x i8> @urem_constant_op0_not_undef_lane(i8 %x) {
 
 define <2 x i8> @urem_constant_op1(i8 %x) {
 ; CHECK-LABEL: @urem_constant_op1(
-; CHECK-NEXT:    ret <2 x i8> undef
+; CHECK-NEXT:    ret <2 x i8> poison
 ;
   %ins = insertelement <2 x i8> poison, i8 %x, i32 1
   %bo = urem <2 x i8> %ins, <i8 undef, i8 2>
@@ -289,7 +289,7 @@ define <2 x i8> @srem_constant_op0_not_undef_lane(i8 %x) {
 
 define <2 x i8> @srem_constant_op1(i8 %x) {
 ; CHECK-LABEL: @srem_constant_op1(
-; CHECK-NEXT:    ret <2 x i8> undef
+; CHECK-NEXT:    ret <2 x i8> poison
 ;
   %ins = insertelement <2 x i8> poison, i8 %x, i32 1
   %bo = srem <2 x i8> %ins, <i8 undef, i8 2>
@@ -331,7 +331,7 @@ define <2 x i8> @udiv_constant_op0_not_undef_lane(i8 %x) {
 
 define <2 x i8> @udiv_constant_op1(i8 %x) {
 ; CHECK-LABEL: @udiv_constant_op1(
-; CHECK-NEXT:    ret <2 x i8> undef
+; CHECK-NEXT:    ret <2 x i8> poison
 ;
   %ins = insertelement <2 x i8> poison, i8 %x, i32 1
   %bo = udiv <2 x i8> %ins, <i8 undef, i8 2>
@@ -373,7 +373,7 @@ define <2 x i8> @sdiv_constant_op0_not_undef_lane(i8 %x) {
 
 define <2 x i8> @sdiv_constant_op1(i8 %x) {
 ; CHECK-LABEL: @sdiv_constant_op1(
-; CHECK-NEXT:    ret <2 x i8> undef
+; CHECK-NEXT:    ret <2 x i8> poison
 ;
   %ins = insertelement <2 x i8> poison, i8 %x, i32 1
   %bo = sdiv exact <2 x i8> %ins, <i8 undef, i8 2>

diff  --git a/llvm/test/Transforms/InstCombine/inselt-binop.ll b/llvm/test/Transforms/InstCombine/inselt-binop.ll
index 64296c9fd5ad..1d979f9e1e81 100644
--- a/llvm/test/Transforms/InstCombine/inselt-binop.ll
+++ b/llvm/test/Transforms/InstCombine/inselt-binop.ll
@@ -247,7 +247,7 @@ define <2 x i8> @urem_constant_op0_not_undef_lane(i8 %x) {
 
 define <2 x i8> @urem_constant_op1(i8 %x) {
 ; CHECK-LABEL: @urem_constant_op1(
-; CHECK-NEXT:    ret <2 x i8> undef
+; CHECK-NEXT:    ret <2 x i8> poison
 ;
   %ins = insertelement <2 x i8> undef, i8 %x, i32 1
   %bo = urem <2 x i8> %ins, <i8 undef, i8 2>
@@ -289,7 +289,7 @@ define <2 x i8> @srem_constant_op0_not_undef_lane(i8 %x) {
 
 define <2 x i8> @srem_constant_op1(i8 %x) {
 ; CHECK-LABEL: @srem_constant_op1(
-; CHECK-NEXT:    ret <2 x i8> undef
+; CHECK-NEXT:    ret <2 x i8> poison
 ;
   %ins = insertelement <2 x i8> undef, i8 %x, i32 1
   %bo = srem <2 x i8> %ins, <i8 undef, i8 2>
@@ -331,7 +331,7 @@ define <2 x i8> @udiv_constant_op0_not_undef_lane(i8 %x) {
 
 define <2 x i8> @udiv_constant_op1(i8 %x) {
 ; CHECK-LABEL: @udiv_constant_op1(
-; CHECK-NEXT:    ret <2 x i8> undef
+; CHECK-NEXT:    ret <2 x i8> poison
 ;
   %ins = insertelement <2 x i8> undef, i8 %x, i32 1
   %bo = udiv <2 x i8> %ins, <i8 undef, i8 2>
@@ -373,7 +373,7 @@ define <2 x i8> @sdiv_constant_op0_not_undef_lane(i8 %x) {
 
 define <2 x i8> @sdiv_constant_op1(i8 %x) {
 ; CHECK-LABEL: @sdiv_constant_op1(
-; CHECK-NEXT:    ret <2 x i8> undef
+; CHECK-NEXT:    ret <2 x i8> poison
 ;
   %ins = insertelement <2 x i8> undef, i8 %x, i32 1
   %bo = sdiv exact <2 x i8> %ins, <i8 undef, i8 2>

diff  --git a/llvm/test/Transforms/InstCombine/rem.ll b/llvm/test/Transforms/InstCombine/rem.ll
index 37d81f2ebf6a..8f0172e95212 100644
--- a/llvm/test/Transforms/InstCombine/rem.ll
+++ b/llvm/test/Transforms/InstCombine/rem.ll
@@ -247,7 +247,7 @@ define i32 @test5(i32 %X, i8 %B) {
 
 define i32 @test6(i32 %A) {
 ; CHECK-LABEL: @test6(
-; CHECK-NEXT:    ret i32 undef
+; CHECK-NEXT:    ret i32 poison
 ;
   %B = srem i32 %A, 0	;; undef
   ret i32 %B

diff  --git a/llvm/test/Transforms/InstCombine/sdiv-exact-by-negative-power-of-two.ll b/llvm/test/Transforms/InstCombine/sdiv-exact-by-negative-power-of-two.ll
index e19b7ad9c3db..9c88d1220625 100644
--- a/llvm/test/Transforms/InstCombine/sdiv-exact-by-negative-power-of-two.ll
+++ b/llvm/test/Transforms/InstCombine/sdiv-exact-by-negative-power-of-two.ll
@@ -55,7 +55,7 @@ define <2 x i8> @n4_vec_mixed(<2 x i8> %x) {
 
 define <2 x i8> @n4_vec_undef(<2 x i8> %x) {
 ; CHECK-LABEL: @n4_vec_undef(
-; CHECK-NEXT:    ret <2 x i8> undef
+; CHECK-NEXT:    ret <2 x i8> poison
 ;
   %div = sdiv exact <2 x i8> %x, <i8 -32, i8 undef>
   ret <2 x i8> %div

diff  --git a/llvm/test/Transforms/InstCombine/sdiv-exact-by-power-of-two.ll b/llvm/test/Transforms/InstCombine/sdiv-exact-by-power-of-two.ll
index 282584b9888e..09c9a039fc59 100644
--- a/llvm/test/Transforms/InstCombine/sdiv-exact-by-power-of-two.ll
+++ b/llvm/test/Transforms/InstCombine/sdiv-exact-by-power-of-two.ll
@@ -53,7 +53,7 @@ define <2 x i8> @t4_vec(<2 x i8> %x) {
 
 define <2 x i8> @n5_vec_undef(<2 x i8> %x) {
 ; CHECK-LABEL: @n5_vec_undef(
-; CHECK-NEXT:    ret <2 x i8> undef
+; CHECK-NEXT:    ret <2 x i8> poison
 ;
   %div = sdiv exact <2 x i8> %x, <i8 32, i8 undef>
   ret <2 x i8> %div

diff  --git a/llvm/test/Transforms/InstCombine/shift.ll b/llvm/test/Transforms/InstCombine/shift.ll
index a64b96882481..6d9d74fd8199 100644
--- a/llvm/test/Transforms/InstCombine/shift.ll
+++ b/llvm/test/Transforms/InstCombine/shift.ll
@@ -662,7 +662,7 @@ define <3 x i32> @test38_nonuniform(<3 x i32> %x) nounwind readnone {
 
 define <2 x i32> @test38_undef(<2 x i32> %x) nounwind readnone {
 ; CHECK-LABEL: @test38_undef(
-; CHECK-NEXT:    ret <2 x i32> undef
+; CHECK-NEXT:    ret <2 x i32> poison
 ;
   %rem = srem <2 x i32> %x, <i32 32, i32 undef>
   %shl = shl <2 x i32> <i32 1, i32 1>, %rem

diff  --git a/llvm/test/Transforms/InstCombine/vector-udiv.ll b/llvm/test/Transforms/InstCombine/vector-udiv.ll
index e16c93265ba9..e8e5f067101a 100644
--- a/llvm/test/Transforms/InstCombine/vector-udiv.ll
+++ b/llvm/test/Transforms/InstCombine/vector-udiv.ll
@@ -42,7 +42,7 @@ define <4 x i32> @test_v4i32_negconst(<4 x i32> %a0) {
 
 define <4 x i32> @test_v4i32_negconst_undef(<4 x i32> %a0) {
 ; CHECK-LABEL: @test_v4i32_negconst_undef(
-; CHECK-NEXT:    ret <4 x i32> undef
+; CHECK-NEXT:    ret <4 x i32> poison
 ;
   %1 = udiv <4 x i32> %a0, <i32 -3, i32 -5, i32 -7, i32 undef>
   ret <4 x i32> %1

diff  --git a/llvm/test/Transforms/InstCombine/vector-urem.ll b/llvm/test/Transforms/InstCombine/vector-urem.ll
index c9b79b219ce2..619fad8f6199 100644
--- a/llvm/test/Transforms/InstCombine/vector-urem.ll
+++ b/llvm/test/Transforms/InstCombine/vector-urem.ll
@@ -21,7 +21,7 @@ define <4 x i32> @test_v4i32_const_pow2(<4 x i32> %a0) {
 
 define <4 x i32> @test_v4i32_const_pow2_undef(<4 x i32> %a0) {
 ; CHECK-LABEL: @test_v4i32_const_pow2_undef(
-; CHECK-NEXT:    ret <4 x i32> undef
+; CHECK-NEXT:    ret <4 x i32> poison
 ;
   %1 = urem <4 x i32> %a0, <i32 1, i32 2, i32 4, i32 undef>
   ret <4 x i32> %1
@@ -71,7 +71,7 @@ define <4 x i32> @test_v4i32_negconst(<4 x i32> %a0) {
 
 define <4 x i32> @test_v4i32_negconst_undef(<4 x i32> %a0) {
 ; CHECK-LABEL: @test_v4i32_negconst_undef(
-; CHECK-NEXT:    ret <4 x i32> undef
+; CHECK-NEXT:    ret <4 x i32> poison
 ;
   %1 = urem <4 x i32> %a0, <i32 -3, i32 -5, i32 -7, i32 undef>
   ret <4 x i32> %1

diff  --git a/llvm/test/Transforms/InstSimplify/div.ll b/llvm/test/Transforms/InstSimplify/div.ll
index d2ba41c5afd7..7c8efc27d3aa 100644
--- a/llvm/test/Transforms/InstSimplify/div.ll
+++ b/llvm/test/Transforms/InstSimplify/div.ll
@@ -43,10 +43,9 @@ define <2 x i8> @udiv_zero_elt_vec_constfold(<2 x i8> %x) {
   ret <2 x i8> %div
 }
 
-; TODO: instsimplify should fold these to poison
 define <2 x i8> @sdiv_zero_elt_vec(<2 x i8> %x) {
 ; CHECK-LABEL: @sdiv_zero_elt_vec(
-; CHECK-NEXT:    ret <2 x i8> undef
+; CHECK-NEXT:    ret <2 x i8> poison
 ;
   %div = sdiv <2 x i8> %x, <i8 -42, i8 0>
   ret <2 x i8> %div
@@ -54,7 +53,7 @@ define <2 x i8> @sdiv_zero_elt_vec(<2 x i8> %x) {
 
 define <2 x i8> @udiv_zero_elt_vec(<2 x i8> %x) {
 ; CHECK-LABEL: @udiv_zero_elt_vec(
-; CHECK-NEXT:    ret <2 x i8> undef
+; CHECK-NEXT:    ret <2 x i8> poison
 ;
   %div = udiv <2 x i8> %x, <i8 0, i8 42>
   ret <2 x i8> %div
@@ -62,7 +61,7 @@ define <2 x i8> @udiv_zero_elt_vec(<2 x i8> %x) {
 
 define <2 x i8> @sdiv_undef_elt_vec(<2 x i8> %x) {
 ; CHECK-LABEL: @sdiv_undef_elt_vec(
-; CHECK-NEXT:    ret <2 x i8> undef
+; CHECK-NEXT:    ret <2 x i8> poison
 ;
   %div = sdiv <2 x i8> %x, <i8 -42, i8 undef>
   ret <2 x i8> %div
@@ -70,7 +69,7 @@ define <2 x i8> @sdiv_undef_elt_vec(<2 x i8> %x) {
 
 define <2 x i8> @udiv_undef_elt_vec(<2 x i8> %x) {
 ; CHECK-LABEL: @udiv_undef_elt_vec(
-; CHECK-NEXT:    ret <2 x i8> undef
+; CHECK-NEXT:    ret <2 x i8> poison
 ;
   %div = udiv <2 x i8> %x, <i8 undef, i8 42>
   ret <2 x i8> %div
@@ -202,7 +201,6 @@ define i8 @sdiv_minusone_divisor() {
   ret i8 %v
 }
 
-; TODO: these should be poison
 define i32 @poison(i32 %x) {
 ; CHECK-LABEL: @poison(
 ; CHECK-NEXT:    ret i32 poison
@@ -211,6 +209,7 @@ define i32 @poison(i32 %x) {
   ret i32 %v
 }
 
+; TODO: this should be poison
 define i32 @poison2(i32 %x) {
 ; CHECK-LABEL: @poison2(
 ; CHECK-NEXT:    ret i32 0
@@ -221,7 +220,7 @@ define i32 @poison2(i32 %x) {
 
 define <2 x i32> @poison3(<2 x i32> %x) {
 ; CHECK-LABEL: @poison3(
-; CHECK-NEXT:    ret <2 x i32> undef
+; CHECK-NEXT:    ret <2 x i32> poison
 ;
   %v = udiv <2 x i32> %x, <i32 poison, i32 1>
   ret <2 x i32> %v

diff  --git a/llvm/test/Transforms/InstSimplify/rem.ll b/llvm/test/Transforms/InstSimplify/rem.ll
index 74b5ea7bfdc7..6aaeb5c70d00 100644
--- a/llvm/test/Transforms/InstSimplify/rem.ll
+++ b/llvm/test/Transforms/InstSimplify/rem.ll
@@ -43,10 +43,9 @@ define <2 x i8> @urem_zero_elt_vec_constfold(<2 x i8> %x) {
   ret <2 x i8> %rem
 }
 
-; TODO: instsimplify should fold these to poison
 define <2 x i8> @srem_zero_elt_vec(<2 x i8> %x) {
 ; CHECK-LABEL: @srem_zero_elt_vec(
-; CHECK-NEXT:    ret <2 x i8> undef
+; CHECK-NEXT:    ret <2 x i8> poison
 ;
   %rem = srem <2 x i8> %x, <i8 -42, i8 0>
   ret <2 x i8> %rem
@@ -54,7 +53,7 @@ define <2 x i8> @srem_zero_elt_vec(<2 x i8> %x) {
 
 define <2 x i8> @urem_zero_elt_vec(<2 x i8> %x) {
 ; CHECK-LABEL: @urem_zero_elt_vec(
-; CHECK-NEXT:    ret <2 x i8> undef
+; CHECK-NEXT:    ret <2 x i8> poison
 ;
   %rem = urem <2 x i8> %x, <i8 0, i8 42>
   ret <2 x i8> %rem
@@ -62,7 +61,7 @@ define <2 x i8> @urem_zero_elt_vec(<2 x i8> %x) {
 
 define <2 x i8> @srem_undef_elt_vec(<2 x i8> %x) {
 ; CHECK-LABEL: @srem_undef_elt_vec(
-; CHECK-NEXT:    ret <2 x i8> undef
+; CHECK-NEXT:    ret <2 x i8> poison
 ;
   %rem = srem <2 x i8> %x, <i8 -42, i8 undef>
   ret <2 x i8> %rem
@@ -70,7 +69,7 @@ define <2 x i8> @srem_undef_elt_vec(<2 x i8> %x) {
 
 define <2 x i8> @urem_undef_elt_vec(<2 x i8> %x) {
 ; CHECK-LABEL: @urem_undef_elt_vec(
-; CHECK-NEXT:    ret <2 x i8> undef
+; CHECK-NEXT:    ret <2 x i8> poison
 ;
   %rem = urem <2 x i8> %x, <i8 undef, i8 42>
   ret <2 x i8> %rem

diff  --git a/llvm/test/Transforms/InstSimplify/undef.ll b/llvm/test/Transforms/InstSimplify/undef.ll
index 80780899e848..024ef15d31e1 100644
--- a/llvm/test/Transforms/InstSimplify/undef.ll
+++ b/llvm/test/Transforms/InstSimplify/undef.ll
@@ -188,7 +188,7 @@ define <4 x i8> @test19(<4 x i8> %a) {
 
 define i32 @test20(i32 %a) {
 ; CHECK-LABEL: @test20(
-; CHECK-NEXT:    ret i32 undef
+; CHECK-NEXT:    ret i32 poison
 ;
   %b = udiv i32 %a, 0
   ret i32 %b
@@ -196,7 +196,7 @@ define i32 @test20(i32 %a) {
 
 define <2 x i32> @test20vec(<2 x i32> %a) {
 ; CHECK-LABEL: @test20vec(
-; CHECK-NEXT:    ret <2 x i32> undef
+; CHECK-NEXT:    ret <2 x i32> poison
 ;
   %b = udiv <2 x i32> %a, zeroinitializer
   ret <2 x i32> %b
@@ -204,7 +204,7 @@ define <2 x i32> @test20vec(<2 x i32> %a) {
 
 define i32 @test21(i32 %a) {
 ; CHECK-LABEL: @test21(
-; CHECK-NEXT:    ret i32 undef
+; CHECK-NEXT:    ret i32 poison
 ;
   %b = sdiv i32 %a, 0
   ret i32 %b
@@ -212,7 +212,7 @@ define i32 @test21(i32 %a) {
 
 define <2 x i32> @test21vec(<2 x i32> %a) {
 ; CHECK-LABEL: @test21vec(
-; CHECK-NEXT:    ret <2 x i32> undef
+; CHECK-NEXT:    ret <2 x i32> poison
 ;
   %b = sdiv <2 x i32> %a, zeroinitializer
   ret <2 x i32> %b
@@ -348,7 +348,7 @@ define i32 @test37() {
 
 define i32 @test38(i32 %a) {
 ; CHECK-LABEL: @test38(
-; CHECK-NEXT:    ret i32 undef
+; CHECK-NEXT:    ret i32 poison
 ;
   %b = udiv i32 %a, undef
   ret i32 %b

diff  --git a/llvm/test/Transforms/SLPVectorizer/X86/alternate-int-inseltpoison.ll b/llvm/test/Transforms/SLPVectorizer/X86/alternate-int-inseltpoison.ll
index 702ab0db2219..8275f4a19e30 100644
--- a/llvm/test/Transforms/SLPVectorizer/X86/alternate-int-inseltpoison.ll
+++ b/llvm/test/Transforms/SLPVectorizer/X86/alternate-int-inseltpoison.ll
@@ -425,7 +425,7 @@ define <8 x i32> @sdiv_v8i32_undefs(<8 x i32> %a) {
 ; CHECK-NEXT:    [[AB5:%.*]] = sdiv i32 [[A5]], 4
 ; CHECK-NEXT:    [[AB6:%.*]] = sdiv i32 [[A6]], 8
 ; CHECK-NEXT:    [[AB7:%.*]] = sdiv i32 [[A7]], 16
-; CHECK-NEXT:    [[TMP1:%.*]] = insertelement <8 x i32> <i32 undef, i32 poison, i32 poison, i32 poison, i32 undef, i32 poison, i32 poison, i32 poison>, i32 [[AB1]], i32 1
+; CHECK-NEXT:    [[TMP1:%.*]] = insertelement <8 x i32> <i32 undef, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>, i32 [[AB1]], i32 1
 ; CHECK-NEXT:    [[TMP2:%.*]] = insertelement <8 x i32> [[TMP1]], i32 [[AB2]], i32 2
 ; CHECK-NEXT:    [[R4:%.*]] = insertelement <8 x i32> [[TMP2]], i32 [[AB3]], i32 3
 ; CHECK-NEXT:    [[R5:%.*]] = insertelement <8 x i32> [[R4]], i32 [[AB5]], i32 5


        


More information about the llvm-branch-commits mailing list