1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt -S -instsimplify < %s | FileCheck %s 3 4define <4 x i32> @test1(<4 x i32> %A) { 5; CHECK-LABEL: @test1( 6; CHECK-NEXT: ret <4 x i32> undef 7; 8 %I = insertelement <4 x i32> %A, i32 5, i64 4294967296 9 ret <4 x i32> %I 10} 11 12define <4 x i32> @test2(<4 x i32> %A) { 13; CHECK-LABEL: @test2( 14; CHECK-NEXT: ret <4 x i32> undef 15; 16 %I = insertelement <4 x i32> %A, i32 5, i64 4 17 ret <4 x i32> %I 18} 19 20define <4 x i32> @test3(<4 x i32> %A) { 21; CHECK-LABEL: @test3( 22; CHECK-NEXT: [[I:%.*]] = insertelement <4 x i32> [[A:%.*]], i32 5, i64 1 23; CHECK-NEXT: ret <4 x i32> [[I]] 24; 25 %I = insertelement <4 x i32> %A, i32 5, i64 1 26 ret <4 x i32> %I 27} 28 29define <4 x i32> @test4(<4 x i32> %A) { 30; CHECK-LABEL: @test4( 31; CHECK-NEXT: ret <4 x i32> undef 32; 33 %I = insertelement <4 x i32> %A, i32 5, i128 100 34 ret <4 x i32> %I 35} 36 37define <4 x i32> @test5(<4 x i32> %A) { 38; CHECK-LABEL: @test5( 39; CHECK-NEXT: ret <4 x i32> undef 40; 41 %I = insertelement <4 x i32> %A, i32 5, i64 undef 42 ret <4 x i32> %I 43} 44 45define <4 x i32> @test5_poison(<4 x i32> %A) { 46; CHECK-LABEL: @test5_poison( 47; CHECK-NEXT: ret <4 x i32> undef 48; 49 %I = insertelement <4 x i32> %A, i32 5, i64 poison 50 ret <4 x i32> %I 51} 52 53define <4 x i32> @elem_poison(<4 x i32> %A) { 54; CHECK-LABEL: @elem_poison( 55; CHECK-NEXT: [[B:%.*]] = insertelement <4 x i32> [[A:%.*]], i32 poison, i32 1 56; CHECK-NEXT: ret <4 x i32> [[B]] 57; 58 %B = insertelement <4 x i32> %A, i32 poison, i32 1 59 ret <4 x i32> %B 60} 61 62; The undef may be replacing a poison value, so it is not safe to just return 'A'. 63 64define <4 x i32> @PR1286(<4 x i32> %A) { 65; CHECK-LABEL: @PR1286( 66; CHECK-NEXT: [[B:%.*]] = insertelement <4 x i32> [[A:%.*]], i32 undef, i32 1 67; CHECK-NEXT: ret <4 x i32> [[B]] 68; 69 %B = insertelement <4 x i32> %A, i32 undef, i32 1 70 ret <4 x i32> %B 71} 72 73; Constant is not poison, so this can simplify. 74 75define <2 x i32> @undef_into_constant_vector_with_variable_index(<2 x i32> %A, i32 %Index) { 76; CHECK-LABEL: @undef_into_constant_vector_with_variable_index( 77; CHECK-NEXT: ret <2 x i32> <i32 42, i32 -42> 78; 79 %B = insertelement <2 x i32> <i32 42, i32 -42>, i32 undef, i32 %Index 80 ret <2 x i32> %B 81} 82 83define <8 x i8> @extract_insert_same_vec_and_index(<8 x i8> %in) { 84; CHECK-LABEL: @extract_insert_same_vec_and_index( 85; CHECK-NEXT: ret <8 x i8> [[IN:%.*]] 86; 87 %val = extractelement <8 x i8> %in, i32 5 88 %vec = insertelement <8 x i8> %in, i8 %val, i32 5 89 ret <8 x i8> %vec 90} 91 92define <8 x i8> @extract_insert_same_vec_and_index2(<8 x i8> %in, i32 %index) { 93; CHECK-LABEL: @extract_insert_same_vec_and_index2( 94; CHECK-NEXT: ret <8 x i8> [[IN:%.*]] 95; 96 %val = extractelement <8 x i8> %in, i32 %index 97 %vec = insertelement <8 x i8> %in, i8 %val, i32 %index 98 ret <8 x i8> %vec 99} 100 101; The insert is in an unreachable block, so it is allowed to point to itself. 102; This would crash via stack overflow. 103 104define void @PR43218() { 105; CHECK-LABEL: @PR43218( 106; CHECK-NEXT: end: 107; CHECK-NEXT: ret void 108; CHECK: unreachable_infloop: 109; CHECK-NEXT: [[EXTRACT:%.*]] = extractelement <2 x i64> [[BOGUS:%.*]], i32 0 110; CHECK-NEXT: [[T0:%.*]] = inttoptr i64 [[EXTRACT]] to i16**** 111; CHECK-NEXT: [[BOGUS]] = insertelement <2 x i64> [[BOGUS]], i64 undef, i32 1 112; CHECK-NEXT: br label [[UNREACHABLE_INFLOOP:%.*]] 113; 114end: 115 ret void 116 117unreachable_infloop: 118 %extract = extractelement <2 x i64> %bogus, i32 0 119 %t0 = inttoptr i64 %extract to i16**** 120 %bogus = insertelement <2 x i64> %bogus, i64 undef, i32 1 121 br label %unreachable_infloop 122} 123