• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
2; RUN: opt < %s -bb-vectorize -bb-vectorize-req-chain-depth=3 -instcombine -gvn -S | FileCheck %s
3
4; Basic depth-3 chain
5define double @test1(double %A1, double %A2, double %B1, double %B2) {
6; CHECK: @test1
7; CHECK: %X1.v.i1.1 = insertelement <2 x double> undef, double %B1, i32 0
8; CHECK: %X1.v.i0.1 = insertelement <2 x double> undef, double %A1, i32 0
9; CHECK: %X1.v.i1.2 = insertelement <2 x double> %X1.v.i1.1, double %B2, i32 1
10; CHECK: %X1.v.i0.2 = insertelement <2 x double> %X1.v.i0.1, double %A2, i32 1
11	%X1 = fsub double %A1, %B1
12	%X2 = fsub double %A2, %B2
13; CHECK: %X1 = fsub <2 x double> %X1.v.i0.2, %X1.v.i1.2
14	%Y1 = fmul double %X1, %A1
15	%Y2 = fmul double %X2, %A2
16; CHECK: %Y1 = fmul <2 x double> %X1, %X1.v.i0.2
17	%Z1 = fadd double %Y1, %B1
18	%Z2 = fadd double %Y2, %B2
19; CHECK: %Z1 = fadd <2 x double> %Y1, %X1.v.i1.2
20	%R  = fmul double %Z1, %Z2
21; CHECK: %Z1.v.r1 = extractelement <2 x double> %Z1, i32 0
22; CHECK: %Z1.v.r2 = extractelement <2 x double> %Z1, i32 1
23; CHECK: %R = fmul double %Z1.v.r1, %Z1.v.r2
24	ret double %R
25; CHECK: ret double %R
26}
27
28; Basic depth-3 chain (last pair permuted)
29define double @test2(double %A1, double %A2, double %B1, double %B2) {
30; CHECK: @test2
31; CHECK: %X1.v.i1.1 = insertelement <2 x double> undef, double %B1, i32 0
32; CHECK: %X1.v.i0.1 = insertelement <2 x double> undef, double %A1, i32 0
33; CHECK: %X1.v.i1.2 = insertelement <2 x double> %X1.v.i1.1, double %B2, i32 1
34; CHECK: %X1.v.i0.2 = insertelement <2 x double> %X1.v.i0.1, double %A2, i32 1
35	%X1 = fsub double %A1, %B1
36	%X2 = fsub double %A2, %B2
37; CHECK: %X1 = fsub <2 x double> %X1.v.i0.2, %X1.v.i1.2
38	%Y1 = fmul double %X1, %A1
39	%Y2 = fmul double %X2, %A2
40; CHECK: %Y1 = fmul <2 x double> %X1, %X1.v.i0.2
41	%Z1 = fadd double %Y2, %B1
42	%Z2 = fadd double %Y1, %B2
43; CHECK: %Z1.v.i0 = shufflevector <2 x double> %Y1, <2 x double> undef, <2 x i32> <i32 1, i32 0>
44; CHECK: %Z1 = fadd <2 x double> %Z1.v.i0, %X1.v.i1.2
45	%R  = fmul double %Z1, %Z2
46; CHECK: %Z1.v.r1 = extractelement <2 x double> %Z1, i32 0
47; CHECK: %Z1.v.r2 = extractelement <2 x double> %Z1, i32 1
48; CHECK: %R = fmul double %Z1.v.r1, %Z1.v.r2
49	ret double %R
50; CHECK: ret double %R
51}
52
53; Basic depth-3 chain (last pair first splat)
54define double @test3(double %A1, double %A2, double %B1, double %B2) {
55; CHECK: @test3
56; CHECK: %X1.v.i1.1 = insertelement <2 x double> undef, double %B1, i32 0
57; CHECK: %X1.v.i0.1 = insertelement <2 x double> undef, double %A1, i32 0
58; CHECK: %X1.v.i1.2 = insertelement <2 x double> %X1.v.i1.1, double %B2, i32 1
59; CHECK: %X1.v.i0.2 = insertelement <2 x double> %X1.v.i0.1, double %A2, i32 1
60	%X1 = fsub double %A1, %B1
61	%X2 = fsub double %A2, %B2
62; CHECK: %X1 = fsub <2 x double> %X1.v.i0.2, %X1.v.i1.2
63	%Y1 = fmul double %X1, %A1
64	%Y2 = fmul double %X2, %A2
65; CHECK: %Y1 = fmul <2 x double> %X1, %X1.v.i0.2
66	%Z1 = fadd double %Y2, %B1
67	%Z2 = fadd double %Y2, %B2
68; CHECK: %Z1.v.i0 = shufflevector <2 x double> %Y1, <2 x double> undef, <2 x i32> <i32 1, i32 1>
69; CHECK: %Z1 = fadd <2 x double> %Z1.v.i0, %X1.v.i1.2
70	%R  = fmul double %Z1, %Z2
71; CHECK: %Z1.v.r1 = extractelement <2 x double> %Z1, i32 0
72; CHECK: %Z1.v.r2 = extractelement <2 x double> %Z1, i32 1
73; CHECK: %R = fmul double %Z1.v.r1, %Z1.v.r2
74	ret double %R
75; CHECK: ret double %R
76}
77
78; Basic depth-3 chain (last pair second splat)
79define double @test4(double %A1, double %A2, double %B1, double %B2) {
80; CHECK: @test4
81; CHECK: %X1.v.i1.1 = insertelement <2 x double> undef, double %B1, i32 0
82; CHECK: %X1.v.i0.1 = insertelement <2 x double> undef, double %A1, i32 0
83; CHECK: %X1.v.i1.2 = insertelement <2 x double> %X1.v.i1.1, double %B2, i32 1
84; CHECK: %X1.v.i0.2 = insertelement <2 x double> %X1.v.i0.1, double %A2, i32 1
85	%X1 = fsub double %A1, %B1
86	%X2 = fsub double %A2, %B2
87; CHECK: %X1 = fsub <2 x double> %X1.v.i0.2, %X1.v.i1.2
88	%Y1 = fmul double %X1, %A1
89	%Y2 = fmul double %X2, %A2
90; CHECK: %Y1 = fmul <2 x double> %X1, %X1.v.i0.2
91	%Z1 = fadd double %Y1, %B1
92	%Z2 = fadd double %Y1, %B2
93; CHECK: %Z1.v.i0 = shufflevector <2 x double> %Y1, <2 x double> undef, <2 x i32> zeroinitializer
94; CHECK: %Z1 = fadd <2 x double> %Z1.v.i0, %X1.v.i1.2
95	%R  = fmul double %Z1, %Z2
96; CHECK: %Z1.v.r1 = extractelement <2 x double> %Z1, i32 0
97; CHECK: %Z1.v.r2 = extractelement <2 x double> %Z1, i32 1
98; CHECK: %R = fmul double %Z1.v.r1, %Z1.v.r2
99	ret double %R
100; CHECK: ret double %R
101}
102
103; Basic depth-3 chain
104define <2 x float> @test5(<2 x float> %A1, <2 x float> %A2, <2 x float> %B1, <2 x float> %B2) {
105; CHECK: @test5
106; CHECK: %X1.v.i1 = shufflevector <2 x float> %B1, <2 x float> %B2, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
107; CHECK: %X1.v.i0 = shufflevector <2 x float> %A1, <2 x float> %A2, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
108	%X1 = fsub <2 x float> %A1, %B1
109	%X2 = fsub <2 x float> %A2, %B2
110; CHECK: %X1 = fsub <4 x float> %X1.v.i0, %X1.v.i1
111	%Y1 = fmul <2 x float> %X1, %A1
112	%Y2 = fmul <2 x float> %X2, %A2
113; CHECK: %Y1 = fmul <4 x float> %X1, %X1.v.i0
114	%Z1 = fadd <2 x float> %Y1, %B1
115	%Z2 = fadd <2 x float> %Y2, %B2
116; CHECK: %Z1 = fadd <4 x float> %Y1, %X1.v.i1
117	%R  = fmul <2 x float> %Z1, %Z2
118; CHECK: %Z1.v.r1 = shufflevector <4 x float> %Z1, <4 x float> undef, <2 x i32> <i32 0, i32 1>
119; CHECK: %Z1.v.r2 = shufflevector <4 x float> %Z1, <4 x float> undef, <2 x i32> <i32 2, i32 3>
120; CHECK: %R = fmul <2 x float> %Z1.v.r1, %Z1.v.r2
121	ret <2 x float> %R
122; CHECK: ret <2 x float> %R
123}
124
125; Basic chain with shuffles
126define <8 x i8> @test6(<8 x i8> %A1, <8 x i8> %A2, <8 x i8> %B1, <8 x i8> %B2) {
127; CHECK: @test6
128; CHECK: %X1.v.i1 = shufflevector <8 x i8> %B1, <8 x i8> %B2, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
129; CHECK: %X1.v.i0 = shufflevector <8 x i8> %A1, <8 x i8> %A2, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
130	%X1 = sub <8 x i8> %A1, %B1
131	%X2 = sub <8 x i8> %A2, %B2
132; CHECK: %X1 = sub <16 x i8> %X1.v.i0, %X1.v.i1
133	%Y1 = mul <8 x i8> %X1, %A1
134	%Y2 = mul <8 x i8> %X2, %A2
135; CHECK: %Y1 = mul <16 x i8> %X1, %X1.v.i0
136	%Z1 = add <8 x i8> %Y1, %B1
137	%Z2 = add <8 x i8> %Y2, %B2
138; CHECK: %Z1 = add <16 x i8> %Y1, %X1.v.i1
139        %Q1 = shufflevector <8 x i8> %Z1, <8 x i8> %Z2, <8 x i32> <i32 15, i32 8, i32 6, i32 1, i32 13, i32 10, i32 4, i32 3>
140        %Q2 = shufflevector <8 x i8> %Z2, <8 x i8> %Z2, <8 x i32> <i32 6, i32 7, i32 0, i32 1, i32 2, i32 4, i32 4, i32 1>
141; CHECK: %Q1.v.i1 = shufflevector <16 x i8> %Z1, <16 x i8> undef, <16 x i32> <i32 8, i32 undef, i32 10, i32 undef, i32 undef, i32 13, i32 undef, i32 15, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
142; CHECK: %Q1 = shufflevector <16 x i8> %Z1, <16 x i8> %Q1.v.i1, <16 x i32> <i32 23, i32 16, i32 6, i32 1, i32 21, i32 18, i32 4, i32 3, i32 14, i32 15, i32 8, i32 9, i32 10, i32 12, i32 12, i32 9>
143	%R  = mul <8 x i8> %Q1, %Q2
144; CHECK: %Q1.v.r1 = shufflevector <16 x i8> %Q1, <16 x i8> undef, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
145; CHECK: %Q1.v.r2 = shufflevector <16 x i8> %Q1, <16 x i8> undef, <8 x i32> <i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
146; CHECK: %R = mul <8 x i8> %Q1.v.r1, %Q1.v.r2
147	ret <8 x i8> %R
148; CHECK: ret <8 x i8> %R
149}
150
151
152