1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s  -loop-vectorize -mtriple=thumbv8-unknown-unknown -mcpu=cortex-a53 -S | FileCheck %s
3
4; This test is reduced from SPECFP 2006 482.sphinx.
5; We expect vectorization with <2 x double> and <2 x float> ops.
6; See https://bugs.llvm.org/show_bug.cgi?id=36280 for more details.
7
8
9target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
10
11@a = external global i32
12@v = external global i32
13@mm = external global float**
14@vv = external global float**
15@ll = external global float*
16
17define i32 @test(float* nocapture readonly %x) {
18; CHECK-LABEL: @test(
19; CHECK-NEXT:  entry:
20; CHECK-NEXT:    [[T:%.*]] = load i32, i32* @v, align 8
21; CHECK-NEXT:    [[T1:%.*]] = load i32, i32* @a, align 4
22; CHECK-NEXT:    br label [[OUTERLOOP:%.*]]
23; CHECK:       outerloop:
24; CHECK-NEXT:    [[T2:%.*]] = phi i32 [ [[V17:%.*]], [[OUTEREND:%.*]] ], [ [[T1]], [[ENTRY:%.*]] ]
25; CHECK-NEXT:    [[J_0136:%.*]] = phi i32 [ [[INC144:%.*]], [[OUTEREND]] ], [ 0, [[ENTRY]] ]
26; CHECK-NEXT:    [[SCORE_1135:%.*]] = phi i32 [ [[CALL142:%.*]], [[OUTEREND]] ], [ -939524096, [[ENTRY]] ]
27; CHECK-NEXT:    [[T3:%.*]] = load float**, float*** @mm, align 4
28; CHECK-NEXT:    [[ARRAYIDX109:%.*]] = getelementptr inbounds float*, float** [[T3]], i32 [[T2]]
29; CHECK-NEXT:    [[T4:%.*]] = load float*, float** [[ARRAYIDX109]], align 4
30; CHECK-NEXT:    [[T5:%.*]] = load float**, float*** @vv, align 4
31; CHECK-NEXT:    [[ARRAYIDX111:%.*]] = getelementptr inbounds float*, float** [[T5]], i32 [[T2]]
32; CHECK-NEXT:    [[T6:%.*]] = load float*, float** [[ARRAYIDX111]], align 4
33; CHECK-NEXT:    [[T7:%.*]] = load float*, float** @ll, align 4
34; CHECK-NEXT:    [[ARRAYIDX113:%.*]] = getelementptr inbounds float, float* [[T7]], i32 [[T2]]
35; CHECK-NEXT:    [[T8:%.*]] = load float, float* [[ARRAYIDX113]], align 4
36; CHECK-NEXT:    [[CONV114:%.*]] = fpext float [[T8]] to double
37; CHECK-NEXT:    [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[T]], 2
38; CHECK-NEXT:    br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
39; CHECK:       vector.ph:
40; CHECK-NEXT:    [[N_MOD_VF:%.*]] = urem i32 [[T]], 2
41; CHECK-NEXT:    [[N_VEC:%.*]] = sub i32 [[T]], [[N_MOD_VF]]
42; CHECK-NEXT:    [[TMP0:%.*]] = insertelement <2 x double> zeroinitializer, double [[CONV114]], i32 0
43; CHECK-NEXT:    br label [[VECTOR_BODY:%.*]]
44; CHECK:       vector.body:
45; CHECK-NEXT:    [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
46; CHECK-NEXT:    [[VEC_PHI:%.*]] = phi <2 x double> [ [[TMP0]], [[VECTOR_PH]] ], [ [[TMP16:%.*]], [[VECTOR_BODY]] ]
47; CHECK-NEXT:    [[TMP1:%.*]] = add i32 [[INDEX]], 0
48; CHECK-NEXT:    [[TMP2:%.*]] = getelementptr inbounds float, float* [[X:%.*]], i32 [[TMP1]]
49; CHECK-NEXT:    [[TMP3:%.*]] = getelementptr inbounds float, float* [[TMP2]], i32 0
50; CHECK-NEXT:    [[TMP4:%.*]] = bitcast float* [[TMP3]] to <2 x float>*
51; CHECK-NEXT:    [[WIDE_LOAD:%.*]] = load <2 x float>, <2 x float>* [[TMP4]], align 4
52; CHECK-NEXT:    [[TMP5:%.*]] = getelementptr inbounds float, float* [[T4]], i32 [[TMP1]]
53; CHECK-NEXT:    [[TMP6:%.*]] = getelementptr inbounds float, float* [[TMP5]], i32 0
54; CHECK-NEXT:    [[TMP7:%.*]] = bitcast float* [[TMP6]] to <2 x float>*
55; CHECK-NEXT:    [[WIDE_LOAD1:%.*]] = load <2 x float>, <2 x float>* [[TMP7]], align 4
56; CHECK-NEXT:    [[TMP8:%.*]] = fsub fast <2 x float> [[WIDE_LOAD]], [[WIDE_LOAD1]]
57; CHECK-NEXT:    [[TMP9:%.*]] = fpext <2 x float> [[TMP8]] to <2 x double>
58; CHECK-NEXT:    [[TMP10:%.*]] = fmul fast <2 x double> [[TMP9]], [[TMP9]]
59; CHECK-NEXT:    [[TMP11:%.*]] = getelementptr inbounds float, float* [[T6]], i32 [[TMP1]]
60; CHECK-NEXT:    [[TMP12:%.*]] = getelementptr inbounds float, float* [[TMP11]], i32 0
61; CHECK-NEXT:    [[TMP13:%.*]] = bitcast float* [[TMP12]] to <2 x float>*
62; CHECK-NEXT:    [[WIDE_LOAD2:%.*]] = load <2 x float>, <2 x float>* [[TMP13]], align 4
63; CHECK-NEXT:    [[TMP14:%.*]] = fpext <2 x float> [[WIDE_LOAD2]] to <2 x double>
64; CHECK-NEXT:    [[TMP15:%.*]] = fmul fast <2 x double> [[TMP10]], [[TMP14]]
65; CHECK-NEXT:    [[TMP16]] = fsub fast <2 x double> [[VEC_PHI]], [[TMP15]]
66; CHECK-NEXT:    [[INDEX_NEXT]] = add i32 [[INDEX]], 2
67; CHECK-NEXT:    [[TMP17:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
68; CHECK-NEXT:    br i1 [[TMP17]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop !0
69; CHECK:       middle.block:
70; CHECK-NEXT:    [[RDX_SHUF:%.*]] = shufflevector <2 x double> [[TMP16]], <2 x double> undef, <2 x i32> <i32 1, i32 undef>
71; CHECK-NEXT:    [[BIN_RDX:%.*]] = fadd fast <2 x double> [[TMP16]], [[RDX_SHUF]]
72; CHECK-NEXT:    [[TMP18:%.*]] = extractelement <2 x double> [[BIN_RDX]], i32 0
73; CHECK-NEXT:    [[CMP_N:%.*]] = icmp eq i32 [[T]], [[N_VEC]]
74; CHECK-NEXT:    br i1 [[CMP_N]], label [[OUTEREND]], label [[SCALAR_PH]]
75; CHECK:       scalar.ph:
76; CHECK-NEXT:    [[BC_RESUME_VAL:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[OUTERLOOP]] ]
77; CHECK-NEXT:    [[BC_MERGE_RDX:%.*]] = phi double [ [[CONV114]], [[OUTERLOOP]] ], [ [[TMP18]], [[MIDDLE_BLOCK]] ]
78; CHECK-NEXT:    br label [[INNERLOOP:%.*]]
79; CHECK:       innerloop:
80; CHECK-NEXT:    [[I_2132:%.*]] = phi i32 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[INC129:%.*]], [[INNERLOOP]] ]
81; CHECK-NEXT:    [[DVAL1_4131:%.*]] = phi double [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[SUB127:%.*]], [[INNERLOOP]] ]
82; CHECK-NEXT:    [[ARRAYIDX119:%.*]] = getelementptr inbounds float, float* [[X]], i32 [[I_2132]]
83; CHECK-NEXT:    [[T9:%.*]] = load float, float* [[ARRAYIDX119]], align 4
84; CHECK-NEXT:    [[ARRAYIDX120:%.*]] = getelementptr inbounds float, float* [[T4]], i32 [[I_2132]]
85; CHECK-NEXT:    [[T10:%.*]] = load float, float* [[ARRAYIDX120]], align 4
86; CHECK-NEXT:    [[SUB121:%.*]] = fsub fast float [[T9]], [[T10]]
87; CHECK-NEXT:    [[CONV122:%.*]] = fpext float [[SUB121]] to double
88; CHECK-NEXT:    [[MUL123:%.*]] = fmul fast double [[CONV122]], [[CONV122]]
89; CHECK-NEXT:    [[ARRAYIDX124:%.*]] = getelementptr inbounds float, float* [[T6]], i32 [[I_2132]]
90; CHECK-NEXT:    [[T11:%.*]] = load float, float* [[ARRAYIDX124]], align 4
91; CHECK-NEXT:    [[CONV125:%.*]] = fpext float [[T11]] to double
92; CHECK-NEXT:    [[MUL126:%.*]] = fmul fast double [[MUL123]], [[CONV125]]
93; CHECK-NEXT:    [[SUB127]] = fsub fast double [[DVAL1_4131]], [[MUL126]]
94; CHECK-NEXT:    [[INC129]] = add nuw nsw i32 [[I_2132]], 1
95; CHECK-NEXT:    [[EXITCOND143:%.*]] = icmp eq i32 [[INC129]], [[T]]
96; CHECK-NEXT:    br i1 [[EXITCOND143]], label [[OUTEREND]], label [[INNERLOOP]], !llvm.loop !2
97; CHECK:       outerend:
98; CHECK-NEXT:    [[SUB127_LCSSA:%.*]] = phi double [ [[SUB127]], [[INNERLOOP]] ], [ [[TMP18]], [[MIDDLE_BLOCK]] ]
99; CHECK-NEXT:    [[CONV138:%.*]] = fptosi double [[SUB127_LCSSA]] to i32
100; CHECK-NEXT:    [[CALL142]] = add nuw nsw i32 [[SCORE_1135]], [[CONV138]]
101; CHECK-NEXT:    [[INC144]] = add nuw nsw i32 [[J_0136]], 1
102; CHECK-NEXT:    [[ARRAYIDX102:%.*]] = getelementptr inbounds i32, i32* @a, i32 [[INC144]]
103; CHECK-NEXT:    [[V17]] = load i32, i32* [[ARRAYIDX102]], align 4
104; CHECK-NEXT:    [[CMP103:%.*]] = icmp sgt i32 [[V17]], -1
105; CHECK-NEXT:    br i1 [[CMP103]], label [[OUTERLOOP]], label [[EXIT:%.*]]
106; CHECK:       exit:
107; CHECK-NEXT:    ret i32 [[CALL142]]
108;
109entry:
110  %t = load i32, i32* @v, align 8
111  %t1 = load i32, i32* @a, align 4
112  br label %outerloop
113
114outerloop:
115  %t2 = phi i32 [ %v17, %outerend ], [ %t1, %entry ]
116  %j.0136 = phi i32 [ %inc144, %outerend ], [ 0, %entry ]
117  %score.1135 = phi i32 [ %call142, %outerend ], [ -939524096, %entry ]
118  %t3 = load float**, float*** @mm, align 4
119  %arrayidx109 = getelementptr inbounds float*, float** %t3, i32 %t2
120  %t4 = load float*, float** %arrayidx109, align 4
121  %t5 = load float**, float*** @vv, align 4
122  %arrayidx111 = getelementptr inbounds float*, float** %t5, i32 %t2
123  %t6 = load float*, float** %arrayidx111, align 4
124  %t7 = load float*, float** @ll, align 4
125  %arrayidx113 = getelementptr inbounds float, float* %t7, i32 %t2
126  %t8 = load float, float* %arrayidx113, align 4
127  %conv114 = fpext float %t8 to double
128  br label %innerloop
129
130innerloop:
131  %i.2132 = phi i32 [ 0, %outerloop ], [ %inc129, %innerloop ]
132  %dval1.4131 = phi double [ %conv114, %outerloop ], [ %sub127, %innerloop ]
133  %arrayidx119 = getelementptr inbounds float, float* %x, i32 %i.2132
134  %t9 = load float, float* %arrayidx119, align 4
135  %arrayidx120 = getelementptr inbounds float, float* %t4, i32 %i.2132
136  %t10 = load float, float* %arrayidx120, align 4
137  %sub121 = fsub fast float %t9, %t10
138  %conv122 = fpext float %sub121 to double
139  %mul123 = fmul fast double %conv122, %conv122
140  %arrayidx124 = getelementptr inbounds float, float* %t6, i32 %i.2132
141  %t11 = load float, float* %arrayidx124, align 4
142  %conv125 = fpext float %t11 to double
143  %mul126 = fmul fast double %mul123, %conv125
144  %sub127 = fsub fast double %dval1.4131, %mul126
145  %inc129 = add nuw nsw i32 %i.2132, 1
146  %exitcond143 = icmp eq i32 %inc129, %t
147  br i1 %exitcond143, label %outerend, label %innerloop
148
149outerend:
150  %sub127.lcssa = phi double [ %sub127, %innerloop ]
151  %conv138 = fptosi double %sub127.lcssa to i32
152  %call142 = add nuw nsw i32 %score.1135, %conv138
153  %inc144 = add nuw nsw i32 %j.0136, 1
154  %arrayidx102 = getelementptr inbounds i32, i32* @a, i32 %inc144
155  %v17 = load i32, i32* %arrayidx102, align 4
156  %cmp103 = icmp sgt i32 %v17, -1
157  br i1 %cmp103, label %outerloop, label %exit
158
159exit:
160  ret i32 %call142
161}
162
163