1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=instsimplify < %s | FileCheck %s
4 define <4 x i32> @test1(<4 x i32> %A) {
6 ; CHECK-NEXT: ret <4 x i32> poison
8 %I = insertelement <4 x i32> %A, i32 5, i64 4294967296
12 define <4 x i32> @test2(<4 x i32> %A) {
13 ; CHECK-LABEL: @test2(
14 ; CHECK-NEXT: ret <4 x i32> poison
16 %I = insertelement <4 x i32> %A, i32 5, i64 4
20 define <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]]
25 %I = insertelement <4 x i32> %A, i32 5, i64 1
29 define <4 x i32> @test4(<4 x i32> %A) {
30 ; CHECK-LABEL: @test4(
31 ; CHECK-NEXT: ret <4 x i32> poison
33 %I = insertelement <4 x i32> %A, i32 5, i128 100
37 define <4 x i32> @test5(<4 x i32> %A) {
38 ; CHECK-LABEL: @test5(
39 ; CHECK-NEXT: ret <4 x i32> poison
41 %I = insertelement <4 x i32> %A, i32 5, i64 undef
45 define <4 x i32> @test5_poison(<4 x i32> %A) {
46 ; CHECK-LABEL: @test5_poison(
47 ; CHECK-NEXT: ret <4 x i32> poison
49 %I = insertelement <4 x i32> %A, i32 5, i64 poison
53 define <4 x i32> @elem_poison(<4 x i32> %A) {
54 ; CHECK-LABEL: @elem_poison(
55 ; CHECK-NEXT: ret <4 x i32> [[A:%.*]]
57 %B = insertelement <4 x i32> %A, i32 poison, i32 1
61 ; The undef may be replacing a poison value, so it is not safe to just return 'A'.
63 define <4 x i32> @PR1286(<4 x i32> %A) {
64 ; CHECK-LABEL: @PR1286(
65 ; CHECK-NEXT: [[B:%.*]] = insertelement <4 x i32> [[A:%.*]], i32 undef, i32 1
66 ; CHECK-NEXT: ret <4 x i32> [[B]]
68 %B = insertelement <4 x i32> %A, i32 undef, i32 1
72 ; Constant is not poison, so this can simplify.
74 define <2 x i32> @undef_into_constant_vector_with_variable_index(<2 x i32> %A, i32 %Index) {
75 ; CHECK-LABEL: @undef_into_constant_vector_with_variable_index(
76 ; CHECK-NEXT: ret <2 x i32> <i32 42, i32 -42>
78 %B = insertelement <2 x i32> <i32 42, i32 -42>, i32 undef, i32 %Index
82 define <8 x i8> @extract_insert_same_vec_and_index(<8 x i8> %in) {
83 ; CHECK-LABEL: @extract_insert_same_vec_and_index(
84 ; CHECK-NEXT: ret <8 x i8> [[IN:%.*]]
86 %val = extractelement <8 x i8> %in, i32 5
87 %vec = insertelement <8 x i8> %in, i8 %val, i32 5
91 define <8 x i8> @extract_insert_same_vec_and_index2(<8 x i8> %in, i32 %index) {
92 ; CHECK-LABEL: @extract_insert_same_vec_and_index2(
93 ; CHECK-NEXT: ret <8 x i8> [[IN:%.*]]
95 %val = extractelement <8 x i8> %in, i32 %index
96 %vec = insertelement <8 x i8> %in, i8 %val, i32 %index
100 ; The insert is in an unreachable block, so it is allowed to point to itself.
101 ; This would crash via stack overflow.
103 define void @PR43218() {
104 ; CHECK-LABEL: @PR43218(
106 ; CHECK-NEXT: ret void
107 ; CHECK: unreachable_infloop:
108 ; CHECK-NEXT: [[EXTRACT:%.*]] = extractelement <2 x i64> [[BOGUS:%.*]], i32 0
109 ; CHECK-NEXT: [[T0:%.*]] = inttoptr i64 [[EXTRACT]] to ptr
110 ; CHECK-NEXT: [[BOGUS]] = insertelement <2 x i64> [[BOGUS]], i64 undef, i32 1
111 ; CHECK-NEXT: br label [[UNREACHABLE_INFLOOP:%.*]]
117 %extract = extractelement <2 x i64> %bogus, i32 0
118 %t0 = inttoptr i64 %extract to ptr
119 %bogus = insertelement <2 x i64> %bogus, i64 undef, i32 1
120 br label %unreachable_infloop