1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 define i32 @extractelement_in_range(<vscale x 4 x i32> %a) {
5 ; CHECK-LABEL: @extractelement_in_range(
6 ; CHECK-NEXT: [[R:%.*]] = extractelement <vscale x 4 x i32> [[A:%.*]], i64 1
7 ; CHECK-NEXT: ret i32 [[R]]
9 %r = extractelement <vscale x 4 x i32> %a, i64 1
13 define i32 @extractelement_maybe_out_of_range(<vscale x 4 x i32> %a) {
14 ; CHECK-LABEL: @extractelement_maybe_out_of_range(
15 ; CHECK-NEXT: [[R:%.*]] = extractelement <vscale x 4 x i32> [[A:%.*]], i64 4
16 ; CHECK-NEXT: ret i32 [[R]]
18 %r = extractelement <vscale x 4 x i32> %a, i64 4
22 define i32 @extractelement_bitcast(float %f) {
23 ; CHECK-LABEL: @extractelement_bitcast(
24 ; CHECK-NEXT: [[R:%.*]] = bitcast float [[F:%.*]] to i32
25 ; CHECK-NEXT: ret i32 [[R]]
27 %vec_float = insertelement <vscale x 4 x float> poison, float %f, i32 0
28 %vec_int = bitcast <vscale x 4 x float> %vec_float to <vscale x 4 x i32>
29 %r = extractelement <vscale x 4 x i32> %vec_int, i32 0
33 define i8 @extractelement_bitcast_to_trunc(<vscale x 2 x i32> %a, i32 %x) {
34 ; CHECK-LABEL: @extractelement_bitcast_to_trunc(
35 ; CHECK-NEXT: [[R:%.*]] = trunc i32 [[X:%.*]] to i8
36 ; CHECK-NEXT: ret i8 [[R]]
38 %vec = insertelement <vscale x 2 x i32> %a, i32 %x, i32 1
39 %vec_cast = bitcast <vscale x 2 x i32> %vec to <vscale x 8 x i8>
40 %r = extractelement <vscale x 8 x i8> %vec_cast, i32 4
44 ; TODO: Instcombine could remove the insert.
45 define i8 @extractelement_bitcast_wrong_insert(<vscale x 2 x i32> %a, i32 %x) {
46 ; CHECK-LABEL: @extractelement_bitcast_wrong_insert(
47 ; CHECK-NEXT: [[VEC:%.*]] = insertelement <vscale x 2 x i32> [[A:%.*]], i32 [[X:%.*]], i32 1
48 ; CHECK-NEXT: [[VEC_CAST:%.*]] = bitcast <vscale x 2 x i32> [[VEC]] to <vscale x 8 x i8>
49 ; CHECK-NEXT: [[R:%.*]] = extractelement <vscale x 8 x i8> [[VEC_CAST]], i32 2
50 ; CHECK-NEXT: ret i8 [[R]]
52 %vec = insertelement <vscale x 2 x i32> %a, i32 %x, i32 1 ; <- This insert could be removed.
53 %vec_cast = bitcast <vscale x 2 x i32> %vec to <vscale x 8 x i8>
54 %r = extractelement <vscale x 8 x i8> %vec_cast, i32 2
58 define i32 @extractelement_shuffle_maybe_out_of_range(i32 %v) {
59 ; CHECK-LABEL: @extractelement_shuffle_maybe_out_of_range(
60 ; CHECK-NEXT: [[IN:%.*]] = insertelement <vscale x 4 x i32> poison, i32 [[V:%.*]], i32 0
61 ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <vscale x 4 x i32> [[IN]], <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer
62 ; CHECK-NEXT: [[R:%.*]] = extractelement <vscale x 4 x i32> [[SPLAT]], i32 4
63 ; CHECK-NEXT: ret i32 [[R]]
65 %in = insertelement <vscale x 4 x i32> poison, i32 %v, i32 0
66 %splat = shufflevector <vscale x 4 x i32> %in, <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer
67 %r = extractelement <vscale x 4 x i32> %splat, i32 4
71 define i32 @extractelement_shuffle_invalid_index(i32 %v) {
72 ; CHECK-LABEL: @extractelement_shuffle_invalid_index(
73 ; CHECK-NEXT: [[IN:%.*]] = insertelement <vscale x 4 x i32> poison, i32 [[V:%.*]], i32 0
74 ; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <vscale x 4 x i32> [[IN]], <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer
75 ; CHECK-NEXT: [[R:%.*]] = extractelement <vscale x 4 x i32> [[SPLAT]], i32 -1
76 ; CHECK-NEXT: ret i32 [[R]]
78 %in = insertelement <vscale x 4 x i32> poison, i32 %v, i32 0
79 %splat = shufflevector <vscale x 4 x i32> %in, <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer
80 %r = extractelement <vscale x 4 x i32> %splat, i32 -1
84 define <vscale x 4 x i32> @extractelement_insertelement_same_positions(<vscale x 4 x i32> %vec) {
85 ; CHECK-LABEL: @extractelement_insertelement_same_positions(
86 ; CHECK-NEXT: ret <vscale x 4 x i32> [[VEC:%.*]]
88 %vec.e0 = extractelement <vscale x 4 x i32> %vec, i32 0
89 %vec.e1 = extractelement <vscale x 4 x i32> %vec, i32 1
90 %vec.e2 = extractelement <vscale x 4 x i32> %vec, i32 2
91 %vec.e3 = extractelement <vscale x 4 x i32> %vec, i32 3
92 %1 = insertelement <vscale x 4 x i32> %vec, i32 %vec.e0, i32 0
93 %2 = insertelement <vscale x 4 x i32> %1, i32 %vec.e1, i32 1
94 %3 = insertelement <vscale x 4 x i32> %2, i32 %vec.e2, i32 2
95 %4 = insertelement <vscale x 4 x i32> %3, i32 %vec.e3, i32 3
96 ret <vscale x 4 x i32> %4
99 define <vscale x 4 x i32> @extractelement_insertelement_diff_positions(<vscale x 4 x i32> %vec) {
100 ; CHECK-LABEL: @extractelement_insertelement_diff_positions(
101 ; CHECK-NEXT: [[VEC_E0:%.*]] = extractelement <vscale x 4 x i32> [[VEC:%.*]], i32 4
102 ; CHECK-NEXT: [[VEC_E1:%.*]] = extractelement <vscale x 4 x i32> [[VEC]], i32 5
103 ; CHECK-NEXT: [[VEC_E2:%.*]] = extractelement <vscale x 4 x i32> [[VEC]], i32 6
104 ; CHECK-NEXT: [[VEC_E3:%.*]] = extractelement <vscale x 4 x i32> [[VEC]], i32 7
105 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <vscale x 4 x i32> [[VEC]], i32 [[VEC_E0]], i32 0
106 ; CHECK-NEXT: [[TMP2:%.*]] = insertelement <vscale x 4 x i32> [[TMP1]], i32 [[VEC_E1]], i32 1
107 ; CHECK-NEXT: [[TMP3:%.*]] = insertelement <vscale x 4 x i32> [[TMP2]], i32 [[VEC_E2]], i32 2
108 ; CHECK-NEXT: [[TMP4:%.*]] = insertelement <vscale x 4 x i32> [[TMP3]], i32 [[VEC_E3]], i32 3
109 ; CHECK-NEXT: ret <vscale x 4 x i32> [[TMP4]]
111 %vec.e0 = extractelement <vscale x 4 x i32> %vec, i32 4
112 %vec.e1 = extractelement <vscale x 4 x i32> %vec, i32 5
113 %vec.e2 = extractelement <vscale x 4 x i32> %vec, i32 6
114 %vec.e3 = extractelement <vscale x 4 x i32> %vec, i32 7
115 %1 = insertelement <vscale x 4 x i32> %vec, i32 %vec.e0, i32 0
116 %2 = insertelement <vscale x 4 x i32> %1, i32 %vec.e1, i32 1
117 %3 = insertelement <vscale x 4 x i32> %2, i32 %vec.e2, i32 2
118 %4 = insertelement <vscale x 4 x i32> %3, i32 %vec.e3, i32 3
119 ret <vscale x 4 x i32> %4
122 define i32 @bitcast_of_extractelement( <vscale x 2 x float> %d) {
123 ; CHECK-LABEL: @bitcast_of_extractelement(
124 ; CHECK-NEXT: [[BC:%.*]] = bitcast <vscale x 2 x float> [[D:%.*]] to <vscale x 2 x i32>
125 ; CHECK-NEXT: [[CAST:%.*]] = extractelement <vscale x 2 x i32> [[BC]], i32 0
126 ; CHECK-NEXT: ret i32 [[CAST]]
128 %ext = extractelement <vscale x 2 x float> %d, i32 0
129 %cast = bitcast float %ext to i32
133 define i1 @extractelement_is_zero(<vscale x 2 x i32> %d, i1 %b, i32 %z) {
134 ; CHECK-LABEL: @extractelement_is_zero(
135 ; CHECK-NEXT: [[EXT:%.*]] = extractelement <vscale x 2 x i32> [[D:%.*]], i32 0
136 ; CHECK-NEXT: [[BB:%.*]] = icmp eq i32 [[EXT]], 0
137 ; CHECK-NEXT: ret i1 [[BB]]
139 %ext = extractelement <vscale x 2 x i32> %d, i32 0
140 %bb = icmp eq i32 %ext, 0
145 ; https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=25272
146 define i32 @ossfuzz_25272(float %f) {
147 ; CHECK-LABEL: @ossfuzz_25272(
148 ; CHECK-NEXT: [[VEC_FLOAT:%.*]] = insertelement <vscale x 4 x float> poison, float [[F:%.*]], i32 0
149 ; CHECK-NEXT: [[VEC_INT:%.*]] = bitcast <vscale x 4 x float> [[VEC_FLOAT]] to <vscale x 4 x i32>
150 ; CHECK-NEXT: [[E:%.*]] = extractelement <vscale x 4 x i32> [[VEC_INT]], i32 2147483647
151 ; CHECK-NEXT: ret i32 [[E]]
153 %vec_float = insertelement <vscale x 4 x float> poison, float %f, i32 0
154 %vec_int = bitcast <vscale x 4 x float> %vec_float to <vscale x 4 x i32>
155 %E = extractelement <vscale x 4 x i32> %vec_int, i32 2147483647