1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=slp-vectorizer -S | FileCheck %s
4 target triple = "aarch64--linux-gnu"
6 ; This checks that we we prefer splats rather than load vectors + shuffles.
7 ; A load + broadcast can be done efficiently with a single `ld1r` instruction.
8 define void @splat_loads_double(ptr %array1, ptr %array2, ptr %ptrA, ptr %ptrB) {
9 ; CHECK-LABEL: @splat_loads_double(
11 ; CHECK-NEXT: [[GEP_2_1:%.*]] = getelementptr inbounds double, ptr [[ARRAY2:%.*]], i64 1
12 ; CHECK-NEXT: [[LD_2_0:%.*]] = load double, ptr [[ARRAY2]], align 8
13 ; CHECK-NEXT: [[LD_2_1:%.*]] = load double, ptr [[GEP_2_1]], align 8
14 ; CHECK-NEXT: [[TMP0:%.*]] = load <2 x double>, ptr [[ARRAY1:%.*]], align 8
15 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x double> poison, double [[LD_2_0]], i32 0
16 ; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <2 x double> [[TMP1]], <2 x double> poison, <2 x i32> zeroinitializer
17 ; CHECK-NEXT: [[TMP3:%.*]] = fmul <2 x double> [[TMP0]], [[TMP2]]
18 ; CHECK-NEXT: [[TMP4:%.*]] = insertelement <2 x double> poison, double [[LD_2_1]], i32 0
19 ; CHECK-NEXT: [[TMP5:%.*]] = shufflevector <2 x double> [[TMP4]], <2 x double> poison, <2 x i32> zeroinitializer
20 ; CHECK-NEXT: [[TMP6:%.*]] = fmul <2 x double> [[TMP0]], [[TMP5]]
21 ; CHECK-NEXT: [[TMP7:%.*]] = fadd <2 x double> [[TMP3]], [[TMP6]]
22 ; CHECK-NEXT: store <2 x double> [[TMP7]], ptr [[ARRAY1]], align 8
23 ; CHECK-NEXT: ret void
26 %gep_1_1 = getelementptr inbounds double, ptr %array1, i64 1
27 %ld_1_0 = load double, ptr %array1, align 8
28 %ld_1_1 = load double, ptr %gep_1_1, align 8
30 %gep_2_1 = getelementptr inbounds double, ptr %array2, i64 1
31 %ld_2_0 = load double, ptr %array2, align 8
32 %ld_2_1 = load double, ptr %gep_2_1, align 8
34 %mul0 = fmul double %ld_1_0, %ld_2_0
35 %mul1 = fmul double %ld_1_1, %ld_2_0
37 %mul2 = fmul double %ld_1_0, %ld_2_1
38 %mul3 = fmul double %ld_1_1, %ld_2_1
40 %add0 = fadd double %mul0, %mul2
41 %add1 = fadd double %mul1, %mul3
43 store double %add0, ptr %array1
44 store double %add1, ptr %gep_1_1
48 ; Same but with float instead of double
49 define void @splat_loads_float(ptr %array1, ptr %array2, ptr %ptrA, ptr %ptrB) {
50 ; CHECK-LABEL: @splat_loads_float(
52 ; CHECK-NEXT: [[GEP_2_1:%.*]] = getelementptr inbounds float, ptr [[ARRAY2:%.*]], i64 1
53 ; CHECK-NEXT: [[LD_2_0:%.*]] = load float, ptr [[ARRAY2]], align 8
54 ; CHECK-NEXT: [[LD_2_1:%.*]] = load float, ptr [[GEP_2_1]], align 8
55 ; CHECK-NEXT: [[TMP0:%.*]] = load <2 x float>, ptr [[ARRAY1:%.*]], align 8
56 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x float> poison, float [[LD_2_0]], i32 0
57 ; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <2 x float> [[TMP1]], <2 x float> poison, <2 x i32> zeroinitializer
58 ; CHECK-NEXT: [[TMP3:%.*]] = fmul <2 x float> [[TMP0]], [[TMP2]]
59 ; CHECK-NEXT: [[TMP4:%.*]] = insertelement <2 x float> poison, float [[LD_2_1]], i32 0
60 ; CHECK-NEXT: [[TMP5:%.*]] = shufflevector <2 x float> [[TMP4]], <2 x float> poison, <2 x i32> zeroinitializer
61 ; CHECK-NEXT: [[TMP6:%.*]] = fmul <2 x float> [[TMP0]], [[TMP5]]
62 ; CHECK-NEXT: [[TMP7:%.*]] = fadd <2 x float> [[TMP3]], [[TMP6]]
63 ; CHECK-NEXT: store <2 x float> [[TMP7]], ptr [[ARRAY1]], align 4
64 ; CHECK-NEXT: ret void
67 %gep_1_1 = getelementptr inbounds float, ptr %array1, i64 1
68 %ld_1_0 = load float, ptr %array1, align 8
69 %ld_1_1 = load float, ptr %gep_1_1, align 8
71 %gep_2_1 = getelementptr inbounds float, ptr %array2, i64 1
72 %ld_2_0 = load float, ptr %array2, align 8
73 %ld_2_1 = load float, ptr %gep_2_1, align 8
75 %mul0 = fmul float %ld_1_0, %ld_2_0
76 %mul1 = fmul float %ld_1_1, %ld_2_0
78 %mul2 = fmul float %ld_1_0, %ld_2_1
79 %mul3 = fmul float %ld_1_1, %ld_2_1
81 %add0 = fadd float %mul0, %mul2
82 %add1 = fadd float %mul1, %mul3
84 store float %add0, ptr %array1
85 store float %add1, ptr %gep_1_1
90 define void @splat_loads_i64(ptr %array1, ptr %array2, ptr %ptrA, ptr %ptrB) {
91 ; CHECK-LABEL: @splat_loads_i64(
93 ; CHECK-NEXT: [[GEP_2_1:%.*]] = getelementptr inbounds i64, ptr [[ARRAY2:%.*]], i64 1
94 ; CHECK-NEXT: [[LD_2_0:%.*]] = load i64, ptr [[ARRAY2]], align 8
95 ; CHECK-NEXT: [[LD_2_1:%.*]] = load i64, ptr [[GEP_2_1]], align 8
96 ; CHECK-NEXT: [[TMP0:%.*]] = load <2 x i64>, ptr [[ARRAY1:%.*]], align 8
97 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x i64> poison, i64 [[LD_2_0]], i32 0
98 ; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <2 x i64> [[TMP1]], <2 x i64> poison, <2 x i32> zeroinitializer
99 ; CHECK-NEXT: [[TMP3:%.*]] = or <2 x i64> [[TMP0]], [[TMP2]]
100 ; CHECK-NEXT: [[TMP4:%.*]] = insertelement <2 x i64> poison, i64 [[LD_2_1]], i32 0
101 ; CHECK-NEXT: [[TMP5:%.*]] = shufflevector <2 x i64> [[TMP4]], <2 x i64> poison, <2 x i32> zeroinitializer
102 ; CHECK-NEXT: [[TMP6:%.*]] = or <2 x i64> [[TMP0]], [[TMP5]]
103 ; CHECK-NEXT: [[TMP7:%.*]] = add <2 x i64> [[TMP3]], [[TMP6]]
104 ; CHECK-NEXT: store <2 x i64> [[TMP7]], ptr [[ARRAY1]], align 8
105 ; CHECK-NEXT: ret void
108 %gep_1_1 = getelementptr inbounds i64, ptr %array1, i64 1
109 %ld_1_0 = load i64, ptr %array1, align 8
110 %ld_1_1 = load i64, ptr %gep_1_1, align 8
112 %gep_2_1 = getelementptr inbounds i64, ptr %array2, i64 1
113 %ld_2_0 = load i64, ptr %array2, align 8
114 %ld_2_1 = load i64, ptr %gep_2_1, align 8
116 %or0 = or i64 %ld_1_0, %ld_2_0
117 %or1 = or i64 %ld_1_1, %ld_2_0
119 %or2 = or i64 %ld_1_0, %ld_2_1
120 %or3 = or i64 %ld_1_1, %ld_2_1
122 %add0 = add i64 %or0, %or2
123 %add1 = add i64 %or1, %or3
125 store i64 %add0, ptr %array1
126 store i64 %add1, ptr %gep_1_1
131 define void @splat_loads_i32(ptr %array1, ptr %array2, ptr %ptrA, ptr %ptrB) {
132 ; CHECK-LABEL: @splat_loads_i32(
134 ; CHECK-NEXT: [[GEP_2_1:%.*]] = getelementptr inbounds i32, ptr [[ARRAY2:%.*]], i64 1
135 ; CHECK-NEXT: [[LD_2_0:%.*]] = load i32, ptr [[ARRAY2]], align 8
136 ; CHECK-NEXT: [[LD_2_1:%.*]] = load i32, ptr [[GEP_2_1]], align 8
137 ; CHECK-NEXT: [[TMP0:%.*]] = load <2 x i32>, ptr [[ARRAY1:%.*]], align 8
138 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x i32> poison, i32 [[LD_2_0]], i32 0
139 ; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> poison, <2 x i32> zeroinitializer
140 ; CHECK-NEXT: [[TMP3:%.*]] = or <2 x i32> [[TMP0]], [[TMP2]]
141 ; CHECK-NEXT: [[TMP4:%.*]] = insertelement <2 x i32> poison, i32 [[LD_2_1]], i32 0
142 ; CHECK-NEXT: [[TMP5:%.*]] = shufflevector <2 x i32> [[TMP4]], <2 x i32> poison, <2 x i32> zeroinitializer
143 ; CHECK-NEXT: [[TMP6:%.*]] = or <2 x i32> [[TMP0]], [[TMP5]]
144 ; CHECK-NEXT: [[TMP7:%.*]] = add <2 x i32> [[TMP3]], [[TMP6]]
145 ; CHECK-NEXT: store <2 x i32> [[TMP7]], ptr [[ARRAY1]], align 4
146 ; CHECK-NEXT: ret void
149 %gep_1_1 = getelementptr inbounds i32, ptr %array1, i64 1
150 %ld_1_0 = load i32, ptr %array1, align 8
151 %ld_1_1 = load i32, ptr %gep_1_1, align 8
153 %gep_2_1 = getelementptr inbounds i32, ptr %array2, i64 1
154 %ld_2_0 = load i32, ptr %array2, align 8
155 %ld_2_1 = load i32, ptr %gep_2_1, align 8
157 %or0 = or i32 %ld_1_0, %ld_2_0
158 %or1 = or i32 %ld_1_1, %ld_2_0
160 %or2 = or i32 %ld_1_0, %ld_2_1
161 %or3 = or i32 %ld_1_1, %ld_2_1
163 %add0 = add i32 %or0, %or2
164 %add1 = add i32 %or1, %or3
166 store i32 %add0, ptr %array1
167 store i32 %add1, ptr %gep_1_1