1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -loop-vectorize -mtriple=x86_64-apple-darwin %s | FileCheck %s --check-prefixes=CHECK,SSE
3 ; RUN: opt -S -loop-vectorize -mtriple=x86_64-apple-darwin -mattr=+avx %s | FileCheck %s --check-prefixes=CHECK,AVX
5 ; Two mostly identical functions. The only difference is the presence of
6 ; fast-math flags on the second. The loop is a pretty simple reduction:
8 ; for (int i = 0; i < 32; ++i)
12 define double @sumIfScalar(double* nocapture readonly %arr) {
13 ; CHECK-LABEL: @sumIfScalar(
15 ; CHECK-NEXT: br label [[LOOP:%.*]]
17 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[I_NEXT:%.*]], [[NEXT_ITER:%.*]] ]
18 ; CHECK-NEXT: [[TOT:%.*]] = phi double [ 0.000000e+00, [[ENTRY]] ], [ [[TOT_NEXT:%.*]], [[NEXT_ITER]] ]
19 ; CHECK-NEXT: [[ADDR:%.*]] = getelementptr double, double* [[ARR:%.*]], i32 [[I]]
20 ; CHECK-NEXT: [[NEXTVAL:%.*]] = load double, double* [[ADDR]], align 8
21 ; CHECK-NEXT: [[TST:%.*]] = fcmp une double [[NEXTVAL]], 4.200000e+01
22 ; CHECK-NEXT: br i1 [[TST]], label [[DO_ADD:%.*]], label [[NO_ADD:%.*]]
24 ; CHECK-NEXT: [[TOT_NEW:%.*]] = fadd double [[TOT]], [[NEXTVAL]]
25 ; CHECK-NEXT: br label [[NEXT_ITER]]
27 ; CHECK-NEXT: br label [[NEXT_ITER]]
29 ; CHECK-NEXT: [[TOT_NEXT]] = phi double [ [[TOT]], [[NO_ADD]] ], [ [[TOT_NEW]], [[DO_ADD]] ]
30 ; CHECK-NEXT: [[I_NEXT]] = add i32 [[I]], 1
31 ; CHECK-NEXT: [[AGAIN:%.*]] = icmp ult i32 [[I_NEXT]], 32
32 ; CHECK-NEXT: br i1 [[AGAIN]], label [[LOOP]], label [[DONE:%.*]]
34 ; CHECK-NEXT: [[TOT_NEXT_LCSSA:%.*]] = phi double [ [[TOT_NEXT]], [[NEXT_ITER]] ]
35 ; CHECK-NEXT: ret double [[TOT_NEXT_LCSSA]]
41 %i = phi i32 [0, %entry], [%i.next, %next.iter]
42 %tot = phi double [0.0, %entry], [%tot.next, %next.iter]
44 %addr = getelementptr double, double* %arr, i32 %i
45 %nextval = load double, double* %addr
47 %tst = fcmp une double %nextval, 42.0
48 br i1 %tst, label %do.add, label %no.add
51 %tot.new = fadd double %tot, %nextval
58 %tot.next = phi double [%tot, %no.add], [%tot.new, %do.add]
59 %i.next = add i32 %i, 1
60 %again = icmp ult i32 %i.next, 32
61 br i1 %again, label %loop, label %done
67 define double @sumIfVector(double* nocapture readonly %arr) {
68 ; SSE-LABEL: @sumIfVector(
70 ; SSE-NEXT: br label [[LOOP:%.*]]
72 ; SSE-NEXT: [[I:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[I_NEXT:%.*]], [[NEXT_ITER:%.*]] ]
73 ; SSE-NEXT: [[TOT:%.*]] = phi double [ 0.000000e+00, [[ENTRY]] ], [ [[TOT_NEXT:%.*]], [[NEXT_ITER]] ]
74 ; SSE-NEXT: [[ADDR:%.*]] = getelementptr double, double* [[ARR:%.*]], i32 [[I]]
75 ; SSE-NEXT: [[NEXTVAL:%.*]] = load double, double* [[ADDR]], align 8
76 ; SSE-NEXT: [[TST:%.*]] = fcmp fast une double [[NEXTVAL]], 4.200000e+01
77 ; SSE-NEXT: br i1 [[TST]], label [[DO_ADD:%.*]], label [[NO_ADD:%.*]]
79 ; SSE-NEXT: [[TOT_NEW:%.*]] = fadd fast double [[TOT]], [[NEXTVAL]]
80 ; SSE-NEXT: br label [[NEXT_ITER]]
82 ; SSE-NEXT: br label [[NEXT_ITER]]
84 ; SSE-NEXT: [[TOT_NEXT]] = phi double [ [[TOT]], [[NO_ADD]] ], [ [[TOT_NEW]], [[DO_ADD]] ]
85 ; SSE-NEXT: [[I_NEXT]] = add i32 [[I]], 1
86 ; SSE-NEXT: [[AGAIN:%.*]] = icmp ult i32 [[I_NEXT]], 32
87 ; SSE-NEXT: br i1 [[AGAIN]], label [[LOOP]], label [[DONE:%.*]]
89 ; SSE-NEXT: [[TOT_NEXT_LCSSA:%.*]] = phi double [ [[TOT_NEXT]], [[NEXT_ITER]] ]
90 ; SSE-NEXT: ret double [[TOT_NEXT_LCSSA]]
92 ; AVX-LABEL: @sumIfVector(
94 ; AVX-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
96 ; AVX-NEXT: br label [[VECTOR_BODY:%.*]]
98 ; AVX-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
99 ; AVX-NEXT: [[VEC_PHI:%.*]] = phi <4 x double> [ zeroinitializer, [[VECTOR_PH]] ], [ [[PREDPHI:%.*]], [[VECTOR_BODY]] ]
100 ; AVX-NEXT: [[TMP0:%.*]] = add i32 [[INDEX]], 0
101 ; AVX-NEXT: [[TMP1:%.*]] = getelementptr double, double* [[ARR:%.*]], i32 [[TMP0]]
102 ; AVX-NEXT: [[TMP2:%.*]] = getelementptr double, double* [[TMP1]], i32 0
103 ; AVX-NEXT: [[TMP3:%.*]] = bitcast double* [[TMP2]] to <4 x double>*
104 ; AVX-NEXT: [[WIDE_LOAD:%.*]] = load <4 x double>, <4 x double>* [[TMP3]], align 8
105 ; AVX-NEXT: [[TMP4:%.*]] = fcmp fast une <4 x double> [[WIDE_LOAD]], <double 4.200000e+01, double 4.200000e+01, double 4.200000e+01, double 4.200000e+01>
106 ; AVX-NEXT: [[TMP5:%.*]] = fadd fast <4 x double> [[VEC_PHI]], [[WIDE_LOAD]]
107 ; AVX-NEXT: [[TMP6:%.*]] = xor <4 x i1> [[TMP4]], <i1 true, i1 true, i1 true, i1 true>
108 ; AVX-NEXT: [[PREDPHI]] = select <4 x i1> [[TMP4]], <4 x double> [[TMP5]], <4 x double> [[VEC_PHI]]
109 ; AVX-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4
110 ; AVX-NEXT: [[TMP7:%.*]] = icmp eq i32 [[INDEX_NEXT]], 32
111 ; AVX-NEXT: br i1 [[TMP7]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], [[LOOP0:!llvm.loop !.*]]
113 ; AVX-NEXT: [[TMP8:%.*]] = call fast double @llvm.vector.reduce.fadd.v4f64(double -0.000000e+00, <4 x double> [[PREDPHI]])
114 ; AVX-NEXT: [[CMP_N:%.*]] = icmp eq i32 32, 32
115 ; AVX-NEXT: br i1 [[CMP_N]], label [[DONE:%.*]], label [[SCALAR_PH]]
117 ; AVX-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ 32, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
118 ; AVX-NEXT: [[BC_MERGE_RDX:%.*]] = phi double [ 0.000000e+00, [[ENTRY]] ], [ [[TMP8]], [[MIDDLE_BLOCK]] ]
119 ; AVX-NEXT: br label [[LOOP:%.*]]
121 ; AVX-NEXT: [[I:%.*]] = phi i32 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[I_NEXT:%.*]], [[NEXT_ITER:%.*]] ]
122 ; AVX-NEXT: [[TOT:%.*]] = phi double [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[TOT_NEXT:%.*]], [[NEXT_ITER]] ]
123 ; AVX-NEXT: [[ADDR:%.*]] = getelementptr double, double* [[ARR]], i32 [[I]]
124 ; AVX-NEXT: [[NEXTVAL:%.*]] = load double, double* [[ADDR]], align 8
125 ; AVX-NEXT: [[TST:%.*]] = fcmp fast une double [[NEXTVAL]], 4.200000e+01
126 ; AVX-NEXT: br i1 [[TST]], label [[DO_ADD:%.*]], label [[NO_ADD:%.*]]
128 ; AVX-NEXT: [[TOT_NEW:%.*]] = fadd fast double [[TOT]], [[NEXTVAL]]
129 ; AVX-NEXT: br label [[NEXT_ITER]]
131 ; AVX-NEXT: br label [[NEXT_ITER]]
133 ; AVX-NEXT: [[TOT_NEXT]] = phi double [ [[TOT]], [[NO_ADD]] ], [ [[TOT_NEW]], [[DO_ADD]] ]
134 ; AVX-NEXT: [[I_NEXT]] = add i32 [[I]], 1
135 ; AVX-NEXT: [[AGAIN:%.*]] = icmp ult i32 [[I_NEXT]], 32
136 ; AVX-NEXT: br i1 [[AGAIN]], label [[LOOP]], label [[DONE]], [[LOOP2:!llvm.loop !.*]]
138 ; AVX-NEXT: [[TOT_NEXT_LCSSA:%.*]] = phi double [ [[TOT_NEXT]], [[NEXT_ITER]] ], [ [[TMP8]], [[MIDDLE_BLOCK]] ]
139 ; AVX-NEXT: ret double [[TOT_NEXT_LCSSA]]
145 %i = phi i32 [0, %entry], [%i.next, %next.iter]
146 %tot = phi double [0.0, %entry], [%tot.next, %next.iter]
148 %addr = getelementptr double, double* %arr, i32 %i
149 %nextval = load double, double* %addr
151 %tst = fcmp fast une double %nextval, 42.0
152 br i1 %tst, label %do.add, label %no.add
155 %tot.new = fadd fast double %tot, %nextval
162 %tot.next = phi double [%tot, %no.add], [%tot.new, %do.add]
163 %i.next = add i32 %i, 1
164 %again = icmp ult i32 %i.next, 32
165 br i1 %again, label %loop, label %done