1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=slp-vectorizer,dce -slp-vectorize-non-power-of-2 -S -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx | FileCheck --check-prefixes=CHECK,NON-POW2 %s
3 ; RUN: opt < %s -passes=slp-vectorizer,dce -slp-vectorize-non-power-of-2=false -S -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx | FileCheck --check-prefixes=CHECK,POW2-ONLY %s
5 ;int foo(char * restrict A, ptr restrict B, float T) {
6 ; A[0] = (T * B[10] + 4.0);
7 ; A[1] = (T * B[11] + 5.0);
8 ; A[2] = (T * B[12] + 6.0);
11 define i32 @foo(ptr noalias nocapture %A, ptr noalias nocapture %B, float %T) {
13 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds float, ptr [[B:%.*]], i64 10
14 ; CHECK-NEXT: [[TMP2:%.*]] = load float, ptr [[TMP1]], align 4
15 ; CHECK-NEXT: [[TMP3:%.*]] = fmul float [[TMP2]], [[T:%.*]]
16 ; CHECK-NEXT: [[TMP4:%.*]] = fpext float [[TMP3]] to double
17 ; CHECK-NEXT: [[TMP5:%.*]] = fadd double [[TMP4]], 4.000000e+00
18 ; CHECK-NEXT: [[TMP6:%.*]] = fptosi double [[TMP5]] to i8
19 ; CHECK-NEXT: store i8 [[TMP6]], ptr [[A:%.*]], align 1
20 ; CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds float, ptr [[B]], i64 11
21 ; CHECK-NEXT: [[TMP8:%.*]] = load float, ptr [[TMP7]], align 4
22 ; CHECK-NEXT: [[TMP9:%.*]] = fmul float [[TMP8]], [[T]]
23 ; CHECK-NEXT: [[TMP10:%.*]] = fpext float [[TMP9]] to double
24 ; CHECK-NEXT: [[TMP11:%.*]] = fadd double [[TMP10]], 5.000000e+00
25 ; CHECK-NEXT: [[TMP12:%.*]] = fptosi double [[TMP11]] to i8
26 ; CHECK-NEXT: [[TMP13:%.*]] = getelementptr inbounds i8, ptr [[A]], i64 1
27 ; CHECK-NEXT: store i8 [[TMP12]], ptr [[TMP13]], align 1
28 ; CHECK-NEXT: [[TMP14:%.*]] = getelementptr inbounds float, ptr [[B]], i64 12
29 ; CHECK-NEXT: [[TMP15:%.*]] = load float, ptr [[TMP14]], align 4
30 ; CHECK-NEXT: [[TMP16:%.*]] = fmul float [[TMP15]], [[T]]
31 ; CHECK-NEXT: [[TMP17:%.*]] = fpext float [[TMP16]] to double
32 ; CHECK-NEXT: [[TMP18:%.*]] = fadd double [[TMP17]], 6.000000e+00
33 ; CHECK-NEXT: [[TMP19:%.*]] = fptosi double [[TMP18]] to i8
34 ; CHECK-NEXT: [[TMP20:%.*]] = getelementptr inbounds i8, ptr [[A]], i64 2
35 ; CHECK-NEXT: store i8 [[TMP19]], ptr [[TMP20]], align 1
36 ; CHECK-NEXT: ret i32 undef
38 %1 = getelementptr inbounds float, ptr %B, i64 10
39 %2 = load float, ptr %1, align 4
40 %3 = fmul float %2, %T
41 %4 = fpext float %3 to double
42 %5 = fadd double %4, 4.000000e+00
43 %6 = fptosi double %5 to i8
44 store i8 %6, ptr %A, align 1
45 %7 = getelementptr inbounds float, ptr %B, i64 11
46 %8 = load float, ptr %7, align 4
47 %9 = fmul float %8, %T
48 %10 = fpext float %9 to double
49 %11 = fadd double %10, 5.000000e+00
50 %12 = fptosi double %11 to i8
51 %13 = getelementptr inbounds i8, ptr %A, i64 1
52 store i8 %12, ptr %13, align 1
53 %14 = getelementptr inbounds float, ptr %B, i64 12
54 %15 = load float, ptr %14, align 4
55 %16 = fmul float %15, %T
56 %17 = fpext float %16 to double
57 %18 = fadd double %17, 6.000000e+00
58 %19 = fptosi double %18 to i8
59 %20 = getelementptr inbounds i8, ptr %A, i64 2
60 store i8 %19, ptr %20, align 1
65 define void @test_v4f32_v2f32_store(<4 x float> %f, ptr %p){
66 ; CHECK-LABEL: @test_v4f32_v2f32_store(
67 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x float> [[F:%.*]], <4 x float> poison, <2 x i32> <i32 0, i32 1>
68 ; CHECK-NEXT: store <2 x float> [[TMP1]], ptr [[P:%.*]], align 4
69 ; CHECK-NEXT: ret void
71 %x0 = extractelement <4 x float> %f, i64 0
72 %x1 = extractelement <4 x float> %f, i64 1
73 %p1 = getelementptr inbounds float, ptr %p, i64 1
74 store float %x0, ptr %p, align 4
75 store float %x1, ptr %p1, align 4
79 define void @test_v4f32_v2f32_splat_store(<4 x float> %f, ptr %p){
80 ; CHECK-LABEL: @test_v4f32_v2f32_splat_store(
81 ; CHECK-NEXT: [[X0:%.*]] = extractelement <4 x float> [[F:%.*]], i64 0
82 ; CHECK-NEXT: [[P1:%.*]] = getelementptr inbounds float, ptr [[P:%.*]], i64 1
83 ; CHECK-NEXT: store float [[X0]], ptr [[P]], align 4
84 ; CHECK-NEXT: store float [[X0]], ptr [[P1]], align 4
85 ; CHECK-NEXT: ret void
87 %x0 = extractelement <4 x float> %f, i64 0
88 %p1 = getelementptr inbounds float, ptr %p, i64 1
89 store float %x0, ptr %p, align 4
90 store float %x0, ptr %p1, align 4
94 define void @test_v4f32_v3f32_store(<4 x float> %f, ptr %p){
95 ; NON-POW2-LABEL: @test_v4f32_v3f32_store(
96 ; NON-POW2-NEXT: [[TMP1:%.*]] = shufflevector <4 x float> [[F:%.*]], <4 x float> poison, <3 x i32> <i32 0, i32 1, i32 2>
97 ; NON-POW2-NEXT: store <3 x float> [[TMP1]], ptr [[P:%.*]], align 4
98 ; NON-POW2-NEXT: ret void
100 ; POW2-ONLY-LABEL: @test_v4f32_v3f32_store(
101 ; POW2-ONLY-NEXT: [[X2:%.*]] = extractelement <4 x float> [[F:%.*]], i64 2
102 ; POW2-ONLY-NEXT: [[P2:%.*]] = getelementptr inbounds float, ptr [[P:%.*]], i64 2
103 ; POW2-ONLY-NEXT: [[TMP1:%.*]] = shufflevector <4 x float> [[F]], <4 x float> poison, <2 x i32> <i32 0, i32 1>
104 ; POW2-ONLY-NEXT: store <2 x float> [[TMP1]], ptr [[P]], align 4
105 ; POW2-ONLY-NEXT: store float [[X2]], ptr [[P2]], align 4
106 ; POW2-ONLY-NEXT: ret void
108 %x0 = extractelement <4 x float> %f, i64 0
109 %x1 = extractelement <4 x float> %f, i64 1
110 %x2 = extractelement <4 x float> %f, i64 2
111 %p1 = getelementptr inbounds float, ptr %p, i64 1
112 %p2 = getelementptr inbounds float, ptr %p, i64 2
113 store float %x0, ptr %p, align 4
114 store float %x1, ptr %p1, align 4
115 store float %x2, ptr %p2, align 4
119 define void @test_v4f32_v3f32_splat_store(<4 x float> %f, ptr %p){
120 ; CHECK-LABEL: @test_v4f32_v3f32_splat_store(
121 ; CHECK-NEXT: [[X0:%.*]] = extractelement <4 x float> [[F:%.*]], i64 0
122 ; CHECK-NEXT: [[P1:%.*]] = getelementptr inbounds float, ptr [[P:%.*]], i64 1
123 ; CHECK-NEXT: [[P2:%.*]] = getelementptr inbounds float, ptr [[P]], i64 2
124 ; CHECK-NEXT: store float [[X0]], ptr [[P]], align 4
125 ; CHECK-NEXT: store float [[X0]], ptr [[P1]], align 4
126 ; CHECK-NEXT: store float [[X0]], ptr [[P2]], align 4
127 ; CHECK-NEXT: ret void
129 %x0 = extractelement <4 x float> %f, i64 0
130 %p1 = getelementptr inbounds float, ptr %p, i64 1
131 %p2 = getelementptr inbounds float, ptr %p, i64 2
132 store float %x0, ptr %p, align 4
133 store float %x0, ptr %p1, align 4
134 store float %x0, ptr %p2, align 4
138 define void @test_v4f32_v4f32_store(<4 x float> %f, ptr %p){
139 ; CHECK-LABEL: @test_v4f32_v4f32_store(
140 ; CHECK-NEXT: store <4 x float> [[F:%.*]], ptr [[P:%.*]], align 4
141 ; CHECK-NEXT: ret void
143 %x0 = extractelement <4 x float> %f, i64 0
144 %x1 = extractelement <4 x float> %f, i64 1
145 %x2 = extractelement <4 x float> %f, i64 2
146 %x3 = extractelement <4 x float> %f, i64 3
147 %p1 = getelementptr inbounds float, ptr %p, i64 1
148 %p2 = getelementptr inbounds float, ptr %p, i64 2
149 %p3 = getelementptr inbounds float, ptr %p, i64 3
150 store float %x0, ptr %p, align 4
151 store float %x1, ptr %p1, align 4
152 store float %x2, ptr %p2, align 4
153 store float %x3, ptr %p3, align 4
157 define void @test_v4f32_v4f32_splat_store(<4 x float> %f, ptr %p){
158 ; CHECK-LABEL: @test_v4f32_v4f32_splat_store(
159 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x float> [[F:%.*]], <4 x float> poison, <4 x i32> zeroinitializer
160 ; CHECK-NEXT: store <4 x float> [[TMP1]], ptr [[P:%.*]], align 4
161 ; CHECK-NEXT: ret void
163 %x0 = extractelement <4 x float> %f, i64 0
164 %p1 = getelementptr inbounds float, ptr %p, i64 1
165 %p2 = getelementptr inbounds float, ptr %p, i64 2
166 %p3 = getelementptr inbounds float, ptr %p, i64 3
167 store float %x0, ptr %p, align 4
168 store float %x0, ptr %p1, align 4
169 store float %x0, ptr %p2, align 4
170 store float %x0, ptr %p3, align 4