[llvm-branch-commits] [llvm] c6ad00d - [InstSimplify] Return poison for out of bounds extractelement

Nikita Popov via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Jan 3 09:21:02 PST 2021


Author: Nikita Popov
Date: 2021-01-03T18:15:58+01:00
New Revision: c6ad00d709853e378cd70e34e755942f9d6f0c8f

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

LOG: [InstSimplify] Return poison for out of bounds extractelement

This is the same change as D93990, but for extractelement rather
than insertelement.

> If idx exceeds the length of val for a fixed-length vector, the
> result is a poison value. For a scalable vector, if the value of
> idx exceeds the runtime length of the vector, the result is a
> poison value.

Added: 
    

Modified: 
    llvm/lib/Analysis/InstructionSimplify.cpp
    llvm/test/Transforms/InstCombine/extractelement-inseltpoison.ll
    llvm/test/Transforms/InstCombine/extractelement.ll
    llvm/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll
    llvm/test/Transforms/InstSimplify/extract-element.ll
    llvm/test/Transforms/InstSimplify/undef.ll
    llvm/test/Transforms/InstSimplify/vscale-inseltpoison.ll
    llvm/test/Transforms/InstSimplify/vscale.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index eb945c60cf94..16b5fd5436f9 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4464,15 +4464,15 @@ static Value *SimplifyExtractElementInst(Value *Vec, Value *Idx,
     // For fixed-length vector, fold into undef if index is out of bounds.
     if (isa<FixedVectorType>(VecVTy) &&
         IdxC->getValue().uge(cast<FixedVectorType>(VecVTy)->getNumElements()))
-      return UndefValue::get(VecVTy->getElementType());
+      return PoisonValue::get(VecVTy->getElementType());
     if (Value *Elt = findScalarElement(Vec, IdxC->getZExtValue()))
       return Elt;
   }
 
   // An undef extract index can be arbitrarily chosen to be an out-of-range
-  // index value, which would result in the instruction being undef.
+  // index value, which would result in the instruction being poison.
   if (Q.isUndefValue(Idx))
-    return UndefValue::get(VecVTy->getElementType());
+    return PoisonValue::get(VecVTy->getElementType());
 
   return nullptr;
 }

diff  --git a/llvm/test/Transforms/InstCombine/extractelement-inseltpoison.ll b/llvm/test/Transforms/InstCombine/extractelement-inseltpoison.ll
index 82c1a5c98294..f3fad9bb375c 100644
--- a/llvm/test/Transforms/InstCombine/extractelement-inseltpoison.ll
+++ b/llvm/test/Transforms/InstCombine/extractelement-inseltpoison.ll
@@ -4,7 +4,7 @@
 
 define i32 @extractelement_out_of_range(<2 x i32> %x) {
 ; ANY-LABEL: @extractelement_out_of_range(
-; ANY-NEXT:    ret i32 undef
+; ANY-NEXT:    ret i32 poison
 ;
   %E1 = extractelement <2 x i32> %x, i8 16
   ret i32 %E1
@@ -319,7 +319,7 @@ define <4 x double> @invalid_extractelement(<2 x double> %a, <4 x double> %b, do
 ; ANY-NEXT:    [[T4:%.*]] = shufflevector <4 x double> [[B:%.*]], <4 x double> [[TMP1]], <4 x i32> <i32 undef, i32 1, i32 4, i32 3>
 ; ANY-NEXT:    [[E:%.*]] = extractelement <4 x double> [[B]], i32 1
 ; ANY-NEXT:    store double [[E]], double* [[P:%.*]], align 8
-; ANY-NEXT:    [[R:%.*]] = insertelement <4 x double> [[T4]], double undef, i64 0
+; ANY-NEXT:    [[R:%.*]] = insertelement <4 x double> [[T4]], double poison, i64 0
 ; ANY-NEXT:    ret <4 x double> [[R]]
 ;
   %t3 = extractelement <2 x double> %a, i32 0

diff  --git a/llvm/test/Transforms/InstCombine/extractelement.ll b/llvm/test/Transforms/InstCombine/extractelement.ll
index 76b7d28b2c09..7d36618452f5 100644
--- a/llvm/test/Transforms/InstCombine/extractelement.ll
+++ b/llvm/test/Transforms/InstCombine/extractelement.ll
@@ -4,7 +4,7 @@
 
 define i32 @extractelement_out_of_range(<2 x i32> %x) {
 ; ANY-LABEL: @extractelement_out_of_range(
-; ANY-NEXT:    ret i32 undef
+; ANY-NEXT:    ret i32 poison
 ;
   %E1 = extractelement <2 x i32> %x, i8 16
   ret i32 %E1
@@ -319,7 +319,7 @@ define <4 x double> @invalid_extractelement(<2 x double> %a, <4 x double> %b, do
 ; ANY-NEXT:    [[T4:%.*]] = shufflevector <4 x double> [[B:%.*]], <4 x double> [[TMP1]], <4 x i32> <i32 undef, i32 1, i32 4, i32 3>
 ; ANY-NEXT:    [[E:%.*]] = extractelement <4 x double> [[B]], i32 1
 ; ANY-NEXT:    store double [[E]], double* [[P:%.*]], align 8
-; ANY-NEXT:    [[R:%.*]] = insertelement <4 x double> [[T4]], double undef, i64 0
+; ANY-NEXT:    [[R:%.*]] = insertelement <4 x double> [[T4]], double poison, i64 0
 ; ANY-NEXT:    ret <4 x double> [[R]]
 ;
   %t3 = extractelement <2 x double> %a, i32 0

diff  --git a/llvm/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll b/llvm/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll
index a0896b4880bd..78acdf27de1a 100644
--- a/llvm/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll
+++ b/llvm/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll
@@ -64,7 +64,7 @@ define i8 @test4(<8 x i8> %V) {
 
 define i32 @test5(<4 x i32> %V) {
 ; CHECK-LABEL: @test5(
-; CHECK-NEXT:    ret i32 undef
+; CHECK-NEXT:    ret i32 poison
 ;
   %extract = extractelement <4 x i32> %V, i32 undef
   ret i32 %extract

diff  --git a/llvm/test/Transforms/InstSimplify/extract-element.ll b/llvm/test/Transforms/InstSimplify/extract-element.ll
index 38e4fd9a2af7..3a9abf63b09d 100644
--- a/llvm/test/Transforms/InstSimplify/extract-element.ll
+++ b/llvm/test/Transforms/InstSimplify/extract-element.ll
@@ -5,7 +5,7 @@
 
 define i129 @vec_extract_negidx(<3 x i129> %a) {
 ; CHECK-LABEL: @vec_extract_negidx(
-; CHECK-NEXT:    ret i129 undef
+; CHECK-NEXT:    ret i129 poison
 ;
   %E1 = extractelement <3 x i129> %a, i129 -1
   ret i129 %E1
@@ -13,7 +13,7 @@ define i129 @vec_extract_negidx(<3 x i129> %a) {
 
 define i129 @vec_extract_out_of_bounds(<3 x i129> %a) {
 ; CHECK-LABEL: @vec_extract_out_of_bounds(
-; CHECK-NEXT:    ret i129 undef
+; CHECK-NEXT:    ret i129 poison
 ;
   %E1 = extractelement <3 x i129> %a, i129 3
   ret i129 %E1
@@ -21,7 +21,7 @@ define i129 @vec_extract_out_of_bounds(<3 x i129> %a) {
 
 define i129 @vec_extract_out_of_bounds2(<3 x i129> %a) {
 ; CHECK-LABEL: @vec_extract_out_of_bounds2(
-; CHECK-NEXT:    ret i129 undef
+; CHECK-NEXT:    ret i129 poison
 ;
   %E1 = extractelement <3 x i129> %a, i129 999999999999999
   ret i129 %E1
@@ -30,7 +30,7 @@ define i129 @vec_extract_out_of_bounds2(<3 x i129> %a) {
 
 define i129 @vec_extract_undef_index(<3 x i129> %a) {
 ; CHECK-LABEL: @vec_extract_undef_index(
-; CHECK-NEXT:    ret i129 undef
+; CHECK-NEXT:    ret i129 poison
 ;
   %E1 = extractelement <3 x i129> %a, i129 undef
   ret i129 %E1
@@ -39,7 +39,7 @@ define i129 @vec_extract_undef_index(<3 x i129> %a) {
 
 define i129 @vec_extract_poison_index(<3 x i129> %a) {
 ; CHECK-LABEL: @vec_extract_poison_index(
-; CHECK-NEXT:    ret i129 undef
+; CHECK-NEXT:    ret i129 poison
 ;
   %E1 = extractelement <3 x i129> %a, i129 poison
   ret i129 %E1

diff  --git a/llvm/test/Transforms/InstSimplify/undef.ll b/llvm/test/Transforms/InstSimplify/undef.ll
index b7c69a5b4e7f..80780899e848 100644
--- a/llvm/test/Transforms/InstSimplify/undef.ll
+++ b/llvm/test/Transforms/InstSimplify/undef.ll
@@ -324,7 +324,7 @@ define i32 @test34(i32 %a) {
 
 define i32 @test35(<4 x i32> %V) {
 ; CHECK-LABEL: @test35(
-; CHECK-NEXT:    ret i32 undef
+; CHECK-NEXT:    ret i32 poison
 ;
   %b = extractelement <4 x i32> %V, i32 4
   ret i32 %b

diff  --git a/llvm/test/Transforms/InstSimplify/vscale-inseltpoison.ll b/llvm/test/Transforms/InstSimplify/vscale-inseltpoison.ll
index c45e6062fde1..6ad1a2dca33e 100644
--- a/llvm/test/Transforms/InstSimplify/vscale-inseltpoison.ll
+++ b/llvm/test/Transforms/InstSimplify/vscale-inseltpoison.ll
@@ -72,7 +72,7 @@ define <vscale x 4 x i32> @insertelement_shufflevector_inline_to_ret() {
 
 define i32 @extractelement_idx_undef(<vscale x 4 x i32> %a) {
 ; CHECK-LABEL: @extractelement_idx_undef(
-; CHECK-NEXT:    ret i32 undef
+; CHECK-NEXT:    ret i32 poison
 ;
   %r = extractelement <vscale x 4 x i32> %a, i64 undef
   ret i32 %r

diff  --git a/llvm/test/Transforms/InstSimplify/vscale.ll b/llvm/test/Transforms/InstSimplify/vscale.ll
index 8533d40bf4af..4cf6f5dc5828 100644
--- a/llvm/test/Transforms/InstSimplify/vscale.ll
+++ b/llvm/test/Transforms/InstSimplify/vscale.ll
@@ -72,7 +72,7 @@ define <vscale x 4 x i32> @insertelement_shufflevector_inline_to_ret() {
 
 define i32 @extractelement_idx_undef(<vscale x 4 x i32> %a) {
 ; CHECK-LABEL: @extractelement_idx_undef(
-; CHECK-NEXT:    ret i32 undef
+; CHECK-NEXT:    ret i32 poison
 ;
   %r = extractelement <vscale x 4 x i32> %a, i64 undef
   ret i32 %r


        


More information about the llvm-branch-commits mailing list