1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -basic-aa -slp-vectorizer -dce -S -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx | FileCheck %s
4 target 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-n8:16:32:64-S128"
5 target triple = "x86_64-apple-macosx10.7.0"
7 @.str = private unnamed_addr constant [6 x i8] c"bingo\00", align 1
9 define void @reduce_compare(double* nocapture %A, i32 %n) {
10 ; CHECK-LABEL: @reduce_compare(
12 ; CHECK-NEXT: [[CONV:%.*]] = sitofp i32 [[N:%.*]] to double
13 ; CHECK-NEXT: [[TMP0:%.*]] = insertelement <2 x double> poison, double [[CONV]], i32 0
14 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x double> [[TMP0]], double [[CONV]], i32 1
15 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
17 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_INC:%.*]] ]
18 ; CHECK-NEXT: [[TMP2:%.*]] = shl nsw i64 [[INDVARS_IV]], 1
19 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds double, double* [[A:%.*]], i64 [[TMP2]]
20 ; CHECK-NEXT: [[TMP3:%.*]] = bitcast double* [[ARRAYIDX]] to <2 x double>*
21 ; CHECK-NEXT: [[TMP4:%.*]] = load <2 x double>, <2 x double>* [[TMP3]], align 8
22 ; CHECK-NEXT: [[TMP5:%.*]] = fmul <2 x double> [[TMP1]], [[TMP4]]
23 ; CHECK-NEXT: [[TMP6:%.*]] = fmul <2 x double> [[TMP5]], <double 7.000000e+00, double 4.000000e+00>
24 ; CHECK-NEXT: [[TMP7:%.*]] = fadd <2 x double> [[TMP6]], <double 5.000000e+00, double 9.000000e+00>
25 ; CHECK-NEXT: [[TMP8:%.*]] = extractelement <2 x double> [[TMP7]], i32 0
26 ; CHECK-NEXT: [[TMP9:%.*]] = extractelement <2 x double> [[TMP7]], i32 1
27 ; CHECK-NEXT: [[CMP11:%.*]] = fcmp ogt double [[TMP8]], [[TMP9]]
28 ; CHECK-NEXT: br i1 [[CMP11]], label [[IF_THEN:%.*]], label [[FOR_INC]]
30 ; CHECK-NEXT: [[CALL:%.*]] = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
31 ; CHECK-NEXT: br label [[FOR_INC]]
33 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add i64 [[INDVARS_IV]], 1
34 ; CHECK-NEXT: [[LFTR_WIDEIV:%.*]] = trunc i64 [[INDVARS_IV_NEXT]] to i32
35 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[LFTR_WIDEIV]], 100
36 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_END:%.*]], label [[FOR_BODY]]
38 ; CHECK-NEXT: ret void
41 %conv = sitofp i32 %n to double
44 for.body: ; preds = %for.inc, %entry
45 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.inc ]
46 %0 = shl nsw i64 %indvars.iv, 1
47 %arrayidx = getelementptr inbounds double, double* %A, i64 %0
48 %1 = load double, double* %arrayidx, align 8
49 %mul1 = fmul double %conv, %1
50 %mul2 = fmul double %mul1, 7.000000e+00
51 %add = fadd double %mul2, 5.000000e+00
53 %arrayidx6 = getelementptr inbounds double, double* %A, i64 %2
54 %3 = load double, double* %arrayidx6, align 8
55 %mul8 = fmul double %conv, %3
56 %mul9 = fmul double %mul8, 4.000000e+00
57 %add10 = fadd double %mul9, 9.000000e+00
58 %cmp11 = fcmp ogt double %add, %add10
59 br i1 %cmp11, label %if.then, label %for.inc
61 if.then: ; preds = %for.body
62 %call = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
65 for.inc: ; preds = %for.body, %if.then
66 %indvars.iv.next = add i64 %indvars.iv, 1
67 %lftr.wideiv = trunc i64 %indvars.iv.next to i32
68 %exitcond = icmp eq i32 %lftr.wideiv, 100
69 br i1 %exitcond, label %for.end, label %for.body
71 for.end: ; preds = %for.inc
75 declare i32 @printf(i8* nocapture, ...)
77 ; PR41312 - the order of the reduction ops should not prevent forming a reduction.
78 ; The 'wrong' member of the reduction requires a greater cost if grouped with the
79 ; other candidates in the reduction because it does not have matching predicate
80 ; and/or constant operand.
82 define float @merge_anyof_v4f32_wrong_first(<4 x float> %x) {
83 ; CHECK-LABEL: @merge_anyof_v4f32_wrong_first(
84 ; CHECK-NEXT: [[TMP1:%.*]] = extractelement <4 x float> [[X:%.*]], i32 3
85 ; CHECK-NEXT: [[CMP3WRONG:%.*]] = fcmp olt float [[TMP1]], 4.200000e+01
86 ; CHECK-NEXT: [[TMP2:%.*]] = fcmp ogt <4 x float> [[X]], <float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00>
87 ; CHECK-NEXT: [[TMP3:%.*]] = call i1 @llvm.vector.reduce.or.v4i1(<4 x i1> [[TMP2]])
88 ; CHECK-NEXT: [[TMP4:%.*]] = or i1 [[TMP3]], [[CMP3WRONG]]
89 ; CHECK-NEXT: [[R:%.*]] = select i1 [[TMP4]], float -1.000000e+00, float 1.000000e+00
90 ; CHECK-NEXT: ret float [[R]]
92 %x0 = extractelement <4 x float> %x, i32 0
93 %x1 = extractelement <4 x float> %x, i32 1
94 %x2 = extractelement <4 x float> %x, i32 2
95 %x3 = extractelement <4 x float> %x, i32 3
96 %cmp3wrong = fcmp olt float %x3, 42.0
97 %cmp0 = fcmp ogt float %x0, 1.0
98 %cmp1 = fcmp ogt float %x1, 1.0
99 %cmp2 = fcmp ogt float %x2, 1.0
100 %cmp3 = fcmp ogt float %x3, 1.0
101 %or03 = or i1 %cmp0, %cmp3wrong
102 %or031 = or i1 %or03, %cmp1
103 %or0312 = or i1 %or031, %cmp2
104 %or03123 = or i1 %or0312, %cmp3
105 %r = select i1 %or03123, float -1.0, float 1.0
109 define float @merge_anyof_v4f32_wrong_last(<4 x float> %x) {
110 ; CHECK-LABEL: @merge_anyof_v4f32_wrong_last(
111 ; CHECK-NEXT: [[TMP1:%.*]] = extractelement <4 x float> [[X:%.*]], i32 3
112 ; CHECK-NEXT: [[CMP3WRONG:%.*]] = fcmp olt float [[TMP1]], 4.200000e+01
113 ; CHECK-NEXT: [[TMP2:%.*]] = fcmp ogt <4 x float> [[X]], <float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00>
114 ; CHECK-NEXT: [[TMP3:%.*]] = call i1 @llvm.vector.reduce.or.v4i1(<4 x i1> [[TMP2]])
115 ; CHECK-NEXT: [[TMP4:%.*]] = or i1 [[TMP3]], [[CMP3WRONG]]
116 ; CHECK-NEXT: [[R:%.*]] = select i1 [[TMP4]], float -1.000000e+00, float 1.000000e+00
117 ; CHECK-NEXT: ret float [[R]]
119 %x0 = extractelement <4 x float> %x, i32 0
120 %x1 = extractelement <4 x float> %x, i32 1
121 %x2 = extractelement <4 x float> %x, i32 2
122 %x3 = extractelement <4 x float> %x, i32 3
123 %cmp3wrong = fcmp olt float %x3, 42.0
124 %cmp0 = fcmp ogt float %x0, 1.0
125 %cmp1 = fcmp ogt float %x1, 1.0
126 %cmp2 = fcmp ogt float %x2, 1.0
127 %cmp3 = fcmp ogt float %x3, 1.0
128 %or03 = or i1 %cmp0, %cmp3
129 %or031 = or i1 %or03, %cmp1
130 %or0312 = or i1 %or031, %cmp2
131 %or03123 = or i1 %or0312, %cmp3wrong
132 %r = select i1 %or03123, float -1.0, float 1.0
136 define i32 @merge_anyof_v4i32_wrong_middle(<4 x i32> %x) {
137 ; CHECK-LABEL: @merge_anyof_v4i32_wrong_middle(
138 ; CHECK-NEXT: [[TMP1:%.*]] = extractelement <4 x i32> [[X:%.*]], i32 3
139 ; CHECK-NEXT: [[CMP3WRONG:%.*]] = icmp slt i32 [[TMP1]], 42
140 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt <4 x i32> [[X]], <i32 1, i32 1, i32 1, i32 1>
141 ; CHECK-NEXT: [[TMP3:%.*]] = call i1 @llvm.vector.reduce.or.v4i1(<4 x i1> [[TMP2]])
142 ; CHECK-NEXT: [[TMP4:%.*]] = or i1 [[TMP3]], [[CMP3WRONG]]
143 ; CHECK-NEXT: [[R:%.*]] = select i1 [[TMP4]], i32 -1, i32 1
144 ; CHECK-NEXT: ret i32 [[R]]
146 %x0 = extractelement <4 x i32> %x, i32 0
147 %x1 = extractelement <4 x i32> %x, i32 1
148 %x2 = extractelement <4 x i32> %x, i32 2
149 %x3 = extractelement <4 x i32> %x, i32 3
150 %cmp3wrong = icmp slt i32 %x3, 42
151 %cmp0 = icmp sgt i32 %x0, 1
152 %cmp1 = icmp sgt i32 %x1, 1
153 %cmp2 = icmp sgt i32 %x2, 1
154 %cmp3 = icmp sgt i32 %x3, 1
155 %or03 = or i1 %cmp0, %cmp3
156 %or033 = or i1 %or03, %cmp3wrong
157 %or0332 = or i1 %or033, %cmp2
158 %or03321 = or i1 %or0332, %cmp1
159 %r = select i1 %or03321, i32 -1, i32 1
163 ; Operand/predicate swapping allows forming a reduction, but the
164 ; ideal reduction groups all of the original 'sgt' ops together.
166 define i32 @merge_anyof_v4i32_wrong_middle_better_rdx(<4 x i32> %x, <4 x i32> %y) {
167 ; CHECK-LABEL: @merge_anyof_v4i32_wrong_middle_better_rdx(
168 ; CHECK-NEXT: [[TMP1:%.*]] = extractelement <4 x i32> [[Y:%.*]], i32 3
169 ; CHECK-NEXT: [[TMP2:%.*]] = extractelement <4 x i32> [[X:%.*]], i32 3
170 ; CHECK-NEXT: [[CMP3WRONG:%.*]] = icmp slt i32 [[TMP2]], [[TMP1]]
171 ; CHECK-NEXT: [[TMP3:%.*]] = icmp sgt <4 x i32> [[X]], [[Y]]
172 ; CHECK-NEXT: [[TMP4:%.*]] = call i1 @llvm.vector.reduce.or.v4i1(<4 x i1> [[TMP3]])
173 ; CHECK-NEXT: [[TMP5:%.*]] = or i1 [[TMP4]], [[CMP3WRONG]]
174 ; CHECK-NEXT: [[R:%.*]] = select i1 [[TMP5]], i32 -1, i32 1
175 ; CHECK-NEXT: ret i32 [[R]]
177 %x0 = extractelement <4 x i32> %x, i32 0
178 %x1 = extractelement <4 x i32> %x, i32 1
179 %x2 = extractelement <4 x i32> %x, i32 2
180 %x3 = extractelement <4 x i32> %x, i32 3
181 %y0 = extractelement <4 x i32> %y, i32 0
182 %y1 = extractelement <4 x i32> %y, i32 1
183 %y2 = extractelement <4 x i32> %y, i32 2
184 %y3 = extractelement <4 x i32> %y, i32 3
185 %cmp3wrong = icmp slt i32 %x3, %y3
186 %cmp0 = icmp sgt i32 %x0, %y0
187 %cmp1 = icmp sgt i32 %x1, %y1
188 %cmp2 = icmp sgt i32 %x2, %y2
189 %cmp3 = icmp sgt i32 %x3, %y3
190 %or03 = or i1 %cmp0, %cmp3
191 %or033 = or i1 %or03, %cmp3wrong
192 %or0332 = or i1 %or033, %cmp2
193 %or03321 = or i1 %or0332, %cmp1
194 %r = select i1 %or03321, i32 -1, i32 1