xref: /llvm-project/llvm/test/Transforms/InstCombine/insert-val-extract-elem.ll (revision 4ab40eca080965c65802710e39adbb78c4ce7bde)
1; RUN: opt -S -passes=instcombine %s | FileCheck %s
2
3; CHECK-LABEL: julia_2xdouble
4; CHECK-NOT: insertvalue
5; CHECK-NOT: extractelement
6; CHECK: store <2 x double>
7define void @julia_2xdouble(ptr sret([2 x double]), ptr) {
8top:
9  %x = load <2 x double>, ptr %1
10  %x0 = extractelement <2 x double> %x, i32 0
11  %i0 = insertvalue [2 x double] undef, double %x0, 0
12  %x1 = extractelement <2 x double> %x, i32 1
13  %i1 = insertvalue [2 x double] %i0, double %x1, 1
14  store [2 x double] %i1, ptr %0, align 4
15  ret void
16}
17
18; Test with two inserts to the same index
19; CHECK-LABEL: julia_2xi64
20; CHECK-NOT: insertvalue
21; CHECK-NOT: extractelement
22; CHECK: store <2 x i64>
23define void @julia_2xi64(ptr sret([2 x i64]), ptr) {
24top:
25  %x = load <2 x i64>, ptr %1
26  %x0 = extractelement <2 x i64> %x, i32 1
27  %i0 = insertvalue [2 x i64] undef, i64 %x0, 0
28  %x1 = extractelement <2 x i64> %x, i32 1
29  %i1 = insertvalue [2 x i64] %i0, i64 %x1, 1
30  %x2 = extractelement <2 x i64> %x, i32 0
31  %i2 = insertvalue [2 x i64] %i1, i64 %x2, 0
32  store [2 x i64] %i2, ptr %0, align 4
33  ret void
34}
35
36; CHECK-LABEL: julia_4xfloat
37; CHECK-NOT: insertvalue
38; CHECK-NOT: extractelement
39; CHECK: store <4 x float>
40define void @julia_4xfloat(ptr sret([4 x float]), ptr) {
41top:
42  %x = load <4 x float>, ptr %1
43  %x0 = extractelement <4 x float> %x, i32 0
44  %i0 = insertvalue [4 x float] undef, float %x0, 0
45  %x1 = extractelement <4 x float> %x, i32 1
46  %i1 = insertvalue [4 x float] %i0, float %x1, 1
47  %x2 = extractelement <4 x float> %x, i32 2
48  %i2 = insertvalue [4 x float] %i1, float %x2, 2
49  %x3 = extractelement <4 x float> %x, i32 3
50  %i3 = insertvalue [4 x float] %i2, float %x3, 3
51  store [4 x float] %i3, ptr %0, align 4
52  ret void
53}
54
55%pseudovec = type { float, float, float, float }
56
57; CHECK-LABEL: julia_pseudovec
58; CHECK-NOT: insertvalue
59; CHECK-NOT: extractelement
60; CHECK: store <4 x float>
61define void @julia_pseudovec(ptr sret(%pseudovec), ptr) {
62top:
63  %x = load <4 x float>, ptr %1
64  %x0 = extractelement <4 x float> %x, i32 0
65  %i0 = insertvalue %pseudovec undef, float %x0, 0
66  %x1 = extractelement <4 x float> %x, i32 1
67  %i1 = insertvalue %pseudovec %i0, float %x1, 1
68  %x2 = extractelement <4 x float> %x, i32 2
69  %i2 = insertvalue %pseudovec %i1, float %x2, 2
70  %x3 = extractelement <4 x float> %x, i32 3
71  %i3 = insertvalue %pseudovec %i2, float %x3, 3
72  store %pseudovec %i3, ptr %0, align 4
73  ret void
74}
75