1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 ; insertelements should fold to shuffle
5 define <4 x float> @foo(<4 x float> %x) {
7 ; CHECK-NEXT: [[INS2:%.*]] = shufflevector <4 x float> %x, <4 x float> <float undef, float 1.000000e+00, float 2.000000e+00, float undef>, <4 x i32> <i32 0, i32 5, i32 6, i32 3>
8 ; CHECK-NEXT: ret <4 x float> [[INS2]]
10 %ins1 = insertelement<4 x float> %x, float 1.0, i32 1
11 %ins2 = insertelement<4 x float> %ins1, float 2.0, i32 2
15 ; Insert of a constant is canonicalized ahead of insert of a variable.
17 define <4 x float> @bar(<4 x float> %x, float %a) {
19 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <4 x float> %x, float 2.000000e+00, i32 2
20 ; CHECK-NEXT: [[INS2:%.*]] = insertelement <4 x float> [[TMP1]], float %a, i32 1
21 ; CHECK-NEXT: ret <4 x float> [[INS2]]
23 %ins1 = insertelement<4 x float> %x, float %a, i32 1
24 %ins2 = insertelement<4 x float> %ins1, float 2.0, i32 2
28 define <4 x float> @baz(<4 x float> %x, i32 %a) {
30 ; CHECK-NEXT: [[INS1:%.*]] = insertelement <4 x float> %x, float 1.000000e+00, i32 1
31 ; CHECK-NEXT: [[INS2:%.*]] = insertelement <4 x float> [[INS1]], float 2.000000e+00, i32 %a
32 ; CHECK-NEXT: ret <4 x float> [[INS2]]
34 %ins1 = insertelement<4 x float> %x, float 1.0, i32 1
35 %ins2 = insertelement<4 x float> %ins1, float 2.0, i32 %a
39 ; insertelements should fold to shuffle
40 define <4 x float> @bazz(<4 x float> %x, i32 %a) {
42 ; CHECK-NEXT: [[INS1:%.*]] = insertelement <4 x float> %x, float 1.000000e+00, i32 3
43 ; CHECK-NEXT: [[INS2:%.*]] = insertelement <4 x float> [[INS1]], float 5.000000e+00, i32 %a
44 ; CHECK-NEXT: [[INS5:%.*]] = shufflevector <4 x float> [[INS2]], <4 x float> <float undef, float 1.000000e+00, float 2.000000e+00, float undef>, <4 x i32> <i32 0, i32 5, i32 6, i32 3>
45 ; CHECK-NEXT: [[INS6:%.*]] = insertelement <4 x float> [[INS5]], float 7.000000e+00, i32 %a
46 ; CHECK-NEXT: ret <4 x float> [[INS6]]
48 %ins1 = insertelement<4 x float> %x, float 1.0, i32 3
49 %ins2 = insertelement<4 x float> %ins1, float 5.0, i32 %a
50 %ins3 = insertelement<4 x float> %ins2, float 3.0, i32 2
51 %ins4 = insertelement<4 x float> %ins3, float 1.0, i32 1
52 %ins5 = insertelement<4 x float> %ins4, float 2.0, i32 2
53 %ins6 = insertelement<4 x float> %ins5, float 7.0, i32 %a
57 ; Out of bounds index folds to undef
58 define <4 x float> @bazzz(<4 x float> %x) {
59 ; CHECK-LABEL: @bazzz(
60 ; CHECK-NEXT: ret <4 x float> <float undef, float undef, float 2.000000e+00, float undef>
62 %ins1 = insertelement<4 x float> %x, float 1.0, i32 5
63 %ins2 = insertelement<4 x float> %ins1, float 2.0, i32 2
67 define <4 x float> @bazzzz(<4 x float> %x) {
68 ; CHECK-LABEL: @bazzzz(
69 ; CHECK-NEXT: ret <4 x float> <float undef, float undef, float 2.000000e+00, float undef>
71 %ins1 = insertelement<4 x float> %x, float 1.0, i32 undef
72 %ins2 = insertelement<4 x float> %ins1, float 2.0, i32 2
76 define <4 x float> @bazzzzz() {
77 ; CHECK-LABEL: @bazzzzz(
78 ; CHECK-NEXT: ret <4 x float> <float 1.000000e+00, float 5.000000e+00, float 1.000000e+01, float 4.000000e+00>
80 %ins1 = insertelement <4 x float> insertelement (<4 x float> <float 1.0, float 2.0, float 3.0, float undef>, float 4.0, i32 3), float 5.0, i32 1
81 %ins2 = insertelement<4 x float> %ins1, float 10.0, i32 2
85 define <4 x float> @bazzzzzz(<4 x float> %x, i32 %a) {
86 ; CHECK-LABEL: @bazzzzzz(
87 ; CHECK-NEXT: ret <4 x float> <float undef, float 5.000000e+00, float undef, float 4.000000e+00>
89 %ins1 = insertelement <4 x float> insertelement (<4 x float> shufflevector (<4 x float> undef, <4 x float> <float 1.0, float 2.0, float 3.0, float 4.0> , <4 x i32> <i32 0, i32 5, i32 undef, i32 6> ), float 4.0, i32 3), float 5.0, i32 1