Author: Juneyoung Lee Date: 2021-01-04T00:43:02+09:00 New Revision: 2139958b53440074fcab9bb2de15e6ec13cc18eb
URL: https://github.com/llvm/llvm-project/commit/2139958b53440074fcab9bb2de15e6ec13cc18eb DIFF: https://github.com/llvm/llvm-project/commit/2139958b53440074fcab9bb2de15e6ec13cc18eb.diff LOG: [InstSimplify] Return poison if insertelement touches out of bounds This is a simple patch that updates InstSimplify to return poison if the index is/can be out-of-bounds Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D93990 Added: Modified: llvm/lib/Analysis/InstructionSimplify.cpp llvm/test/Transforms/InstCombine/out-of-bounds-indexes.ll llvm/test/Transforms/InstCombine/vector_insertelt_shuffle-inseltpoison.ll llvm/test/Transforms/InstCombine/vector_insertelt_shuffle.ll llvm/test/Transforms/InstSimplify/insertelement.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 9fed2600b3ab..eb945c60cf94 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -4385,16 +4385,16 @@ Value *llvm::SimplifyInsertElementInst(Value *Vec, Value *Val, Value *Idx, if (VecC && ValC && IdxC) return ConstantExpr::getInsertElement(VecC, ValC, IdxC); - // For fixed-length vector, fold into undef if index is out of bounds. + // For fixed-length vector, fold into poison if index is out of bounds. if (auto *CI = dyn_cast<ConstantInt>(Idx)) { if (isa<FixedVectorType>(Vec->getType()) && CI->uge(cast<FixedVectorType>(Vec->getType())->getNumElements())) - return UndefValue::get(Vec->getType()); + return PoisonValue::get(Vec->getType()); } // If index is undef, it might be out of bounds (see above case) if (Q.isUndefValue(Idx)) - return UndefValue::get(Vec->getType()); + 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. diff --git a/llvm/test/Transforms/InstCombine/out-of-bounds-indexes.ll b/llvm/test/Transforms/InstCombine/out-of-bounds-indexes.ll index 9559c61dda00..f3b95ed07d44 100644 --- a/llvm/test/Transforms/InstCombine/out-of-bounds-indexes.ll +++ b/llvm/test/Transforms/InstCombine/out-of-bounds-indexes.ll @@ -34,7 +34,7 @@ declare void @llvm.assume(i1) define <4 x double> @inselt_bad_index(<4 x double> %a) { ; CHECK-LABEL: @inselt_bad_index( -; CHECK-NEXT: ret <4 x double> undef +; CHECK-NEXT: ret <4 x double> poison ; %I = insertelement <4 x double> %a, double 0.0, i64 4294967296 ret <4 x double> %I diff --git a/llvm/test/Transforms/InstCombine/vector_insertelt_shuffle-inseltpoison.ll b/llvm/test/Transforms/InstCombine/vector_insertelt_shuffle-inseltpoison.ll index b08e4a7db125..eaa83d4c03f4 100644 --- a/llvm/test/Transforms/InstCombine/vector_insertelt_shuffle-inseltpoison.ll +++ b/llvm/test/Transforms/InstCombine/vector_insertelt_shuffle-inseltpoison.ll @@ -54,10 +54,10 @@ define <4 x float> @bazz(<4 x float> %x, i32 %a) { ret <4 x float> %ins6 } -; Out of bounds index folds to undef +; Out of bounds index folds to poison define <4 x float> @bazzz(<4 x float> %x) { ; CHECK-LABEL: @bazzz( -; CHECK-NEXT: ret <4 x float> <float undef, float undef, float 2.000000e+00, float undef> +; CHECK-NEXT: ret <4 x float> <float poison, float poison, float 2.000000e+00, float poison> ; %ins1 = insertelement<4 x float> %x, float 1.0, i32 5 %ins2 = insertelement<4 x float> %ins1, float 2.0, i32 2 @@ -66,7 +66,7 @@ define <4 x float> @bazzz(<4 x float> %x) { define <4 x float> @bazzzz(<4 x float> %x) { ; CHECK-LABEL: @bazzzz( -; CHECK-NEXT: ret <4 x float> <float undef, float undef, float 2.000000e+00, float undef> +; CHECK-NEXT: ret <4 x float> <float poison, float poison, float 2.000000e+00, float poison> ; %ins1 = insertelement<4 x float> %x, float 1.0, i32 undef %ins2 = insertelement<4 x float> %ins1, float 2.0, i32 2 diff --git a/llvm/test/Transforms/InstCombine/vector_insertelt_shuffle.ll b/llvm/test/Transforms/InstCombine/vector_insertelt_shuffle.ll index 30150af6209b..2635c627c160 100644 --- a/llvm/test/Transforms/InstCombine/vector_insertelt_shuffle.ll +++ b/llvm/test/Transforms/InstCombine/vector_insertelt_shuffle.ll @@ -54,10 +54,10 @@ define <4 x float> @bazz(<4 x float> %x, i32 %a) { ret <4 x float> %ins6 } -; Out of bounds index folds to undef +; Out of bounds index folds to poison define <4 x float> @bazzz(<4 x float> %x) { ; CHECK-LABEL: @bazzz( -; CHECK-NEXT: ret <4 x float> <float undef, float undef, float 2.000000e+00, float undef> +; CHECK-NEXT: ret <4 x float> <float poison, float poison, float 2.000000e+00, float poison> ; %ins1 = insertelement<4 x float> %x, float 1.0, i32 5 %ins2 = insertelement<4 x float> %ins1, float 2.0, i32 2 @@ -66,7 +66,7 @@ define <4 x float> @bazzz(<4 x float> %x) { define <4 x float> @bazzzz(<4 x float> %x) { ; CHECK-LABEL: @bazzzz( -; CHECK-NEXT: ret <4 x float> <float undef, float undef, float 2.000000e+00, float undef> +; CHECK-NEXT: ret <4 x float> <float poison, float poison, float 2.000000e+00, float poison> ; %ins1 = insertelement<4 x float> %x, float 1.0, i32 undef %ins2 = insertelement<4 x float> %ins1, float 2.0, i32 2 diff --git a/llvm/test/Transforms/InstSimplify/insertelement.ll b/llvm/test/Transforms/InstSimplify/insertelement.ll index 6594507c1aad..580670844f22 100644 --- a/llvm/test/Transforms/InstSimplify/insertelement.ll +++ b/llvm/test/Transforms/InstSimplify/insertelement.ll @@ -3,7 +3,7 @@ define <4 x i32> @test1(<4 x i32> %A) { ; CHECK-LABEL: @test1( -; CHECK-NEXT: ret <4 x i32> undef +; CHECK-NEXT: ret <4 x i32> poison ; %I = insertelement <4 x i32> %A, i32 5, i64 4294967296 ret <4 x i32> %I @@ -11,7 +11,7 @@ define <4 x i32> @test1(<4 x i32> %A) { define <4 x i32> @test2(<4 x i32> %A) { ; CHECK-LABEL: @test2( -; CHECK-NEXT: ret <4 x i32> undef +; CHECK-NEXT: ret <4 x i32> poison ; %I = insertelement <4 x i32> %A, i32 5, i64 4 ret <4 x i32> %I @@ -28,7 +28,7 @@ define <4 x i32> @test3(<4 x i32> %A) { define <4 x i32> @test4(<4 x i32> %A) { ; CHECK-LABEL: @test4( -; CHECK-NEXT: ret <4 x i32> undef +; CHECK-NEXT: ret <4 x i32> poison ; %I = insertelement <4 x i32> %A, i32 5, i128 100 ret <4 x i32> %I @@ -36,7 +36,7 @@ define <4 x i32> @test4(<4 x i32> %A) { define <4 x i32> @test5(<4 x i32> %A) { ; CHECK-LABEL: @test5( -; CHECK-NEXT: ret <4 x i32> undef +; CHECK-NEXT: ret <4 x i32> poison ; %I = insertelement <4 x i32> %A, i32 5, i64 undef ret <4 x i32> %I @@ -44,7 +44,7 @@ define <4 x i32> @test5(<4 x i32> %A) { define <4 x i32> @test5_poison(<4 x i32> %A) { ; CHECK-LABEL: @test5_poison( -; CHECK-NEXT: ret <4 x i32> undef +; CHECK-NEXT: ret <4 x i32> poison ; %I = insertelement <4 x i32> %A, i32 5, i64 poison ret <4 x i32> %I diff --git a/llvm/test/Transforms/InstSimplify/vscale-inseltpoison.ll b/llvm/test/Transforms/InstSimplify/vscale-inseltpoison.ll index ba448bc81eee..c45e6062fde1 100644 --- a/llvm/test/Transforms/InstSimplify/vscale-inseltpoison.ll +++ b/llvm/test/Transforms/InstSimplify/vscale-inseltpoison.ll @@ -9,7 +9,7 @@ define <vscale x 4 x i32> @insertelement_idx_undef(<vscale x 4 x i32> %a) { ; CHECK-LABEL: @insertelement_idx_undef( -; CHECK-NEXT: ret <vscale x 4 x i32> undef +; CHECK-NEXT: ret <vscale x 4 x i32> poison ; %r = insertelement <vscale x 4 x i32> %a, i32 5, i64 undef ret <vscale x 4 x i32> %r diff --git a/llvm/test/Transforms/InstSimplify/vscale.ll b/llvm/test/Transforms/InstSimplify/vscale.ll index 802cb9900167..8533d40bf4af 100644 --- a/llvm/test/Transforms/InstSimplify/vscale.ll +++ b/llvm/test/Transforms/InstSimplify/vscale.ll @@ -9,7 +9,7 @@ define <vscale x 4 x i32> @insertelement_idx_undef(<vscale x 4 x i32> %a) { ; CHECK-LABEL: @insertelement_idx_undef( -; CHECK-NEXT: ret <vscale x 4 x i32> undef +; CHECK-NEXT: ret <vscale x 4 x i32> poison ; %r = insertelement <vscale x 4 x i32> %a, i32 5, i64 undef ret <vscale x 4 x i32> %r @@ -133,8 +133,9 @@ define i32 @insert_extract_element_same_vec_idx_4() { define <vscale x 2 x i1> @cmp_le_smax_always_true(<vscale x 2 x i64> %x) { ; CHECK-LABEL: @cmp_le_smax_always_true( ; CHECK-NEXT: ret <vscale x 2 x i1> shufflevector (<vscale x 2 x i1> insertelement (<vscale x 2 x i1> undef, i1 true, i32 0), <vscale x 2 x i1> undef, <vscale x 2 x i32> zeroinitializer) - %cmp = icmp sle <vscale x 2 x i64> %x, shufflevector (<vscale x 2 x i64> insertelement (<vscale x 2 x i64> undef, i64 9223372036854775807, i32 0), <vscale x 2 x i64> undef, <vscale x 2 x i32> zeroinitializer) - ret <vscale x 2 x i1> %cmp +; + %cmp = icmp sle <vscale x 2 x i64> %x, shufflevector (<vscale x 2 x i64> insertelement (<vscale x 2 x i64> undef, i64 9223372036854775807, i32 0), <vscale x 2 x i64> undef, <vscale x 2 x i32> zeroinitializer) + ret <vscale x 2 x i1> %cmp } define <vscale x 4 x float> @bitcast() { _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits