blob: 35c549caf18bfb4136aaba8f96e93557135cb2dc [file] [log] [blame]
Nadav Rotem628c2db2012-12-04 06:15:11 +00001; RUN: opt < %s -loop-vectorize -force-vector-width=4 -enable-if-conversion -dce -instcombine -licm -S | FileCheck %s
2
3target 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"
4target triple = "x86_64-apple-macosx10.9.0"
5
6; This is the loop in this example:
7;
8;int function0(int *a, int *b, int start, int end) {
9;
10; for (int i=start; i<end; ++i) {
11; unsigned k = a[i];
12;
13; if (a[i] > b[i]) <------ notice the IF inside the loop.
14; k = k * 5 + 3;
15;
16; a[i] = k; <---- K is a phi node that becomes vector-select.
17; }
18;}
19
20;CHECK: @function0
21;CHECK: load <4 x i32>
22;CHECK: icmp sgt <4 x i32>
23;CHECK: mul <4 x i32>
24;CHECK: add <4 x i32>
25;CHECK: select <4 x i1>
26;CHECK: ret i32
27define i32 @function0(i32* nocapture %a, i32* nocapture %b, i32 %start, i32 %end) nounwind uwtable ssp {
28entry:
29 %cmp16 = icmp slt i32 %start, %end
30 br i1 %cmp16, label %for.body.lr.ph, label %for.end
31
32for.body.lr.ph:
33 %0 = sext i32 %start to i64
34 br label %for.body
35
36for.body:
37 %indvars.iv = phi i64 [ %0, %for.body.lr.ph ], [ %indvars.iv.next, %if.end ]
38 %arrayidx = getelementptr inbounds i32* %a, i64 %indvars.iv
39 %1 = load i32* %arrayidx, align 4
40 %arrayidx4 = getelementptr inbounds i32* %b, i64 %indvars.iv
41 %2 = load i32* %arrayidx4, align 4
42 %cmp5 = icmp sgt i32 %1, %2
43 br i1 %cmp5, label %if.then, label %if.end
44
45if.then:
46 %mul = mul i32 %1, 5
47 %add = add i32 %mul, 3
48 br label %if.end
49
50if.end:
51 %k.0 = phi i32 [ %add, %if.then ], [ %1, %for.body ]
52 store i32 %k.0, i32* %arrayidx, align 4
53 %indvars.iv.next = add i64 %indvars.iv, 1
54 %3 = trunc i64 %indvars.iv.next to i32
55 %cmp = icmp slt i32 %3, %end
56 br i1 %cmp, label %for.body, label %for.end
57
58for.end:
59 ret i32 undef
60}