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
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.
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
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
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
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
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
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
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
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
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
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
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
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
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() {