1*4455c5cdSSimon Pilgrim; RUN: opt < %s  -passes="print<cost-model>" 2>&1 -disable-output -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx | FileCheck %s
2a6b91ac3SNadav Rotem
3a6b91ac3SNadav Rotemtarget 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"
4a6b91ac3SNadav Rotemtarget triple = "x86_64-apple-macosx10.8.0"
5a6b91ac3SNadav Rotem
6a6b91ac3SNadav Rotemdefine i32 @foo(i32* noalias nocapture %A, i32* noalias nocapture %B, i32 %start, i32 %end) nounwind uwtable ssp {
7a6b91ac3SNadav Rotementry:
8a6b91ac3SNadav Rotem  ;CHECK: cost of 1 {{.*}} icmp
9a6b91ac3SNadav Rotem  %cmp7 = icmp slt i32 %start, %end
10a6b91ac3SNadav Rotem  br i1 %cmp7, label %for.body.lr.ph, label %for.end
11a6b91ac3SNadav Rotem
12a6b91ac3SNadav Rotemfor.body.lr.ph:                                   ; preds = %entry
13a6b91ac3SNadav Rotem  ;CHECK: cost of 1 {{.*}} sext
14a6b91ac3SNadav Rotem  %0 = sext i32 %start to i64
15a6b91ac3SNadav Rotem  %1 = sub i32 %end, %start
16a6b91ac3SNadav Rotem  %2 = zext i32 %1 to i64
17a6b91ac3SNadav Rotem  %end.idx = add i64 %2, %0
18a6b91ac3SNadav Rotem  ;CHECK: cost of 1 {{.*}} add
19a6b91ac3SNadav Rotem  %n.vec = and i64 %2, 4294967288
20a6b91ac3SNadav Rotem  %end.idx.rnd.down = add i64 %n.vec, %0
21a6b91ac3SNadav Rotem  ;CHECK: cost of 1 {{.*}} icmp
22a6b91ac3SNadav Rotem  %cmp.zero = icmp eq i64 %n.vec, 0
23a6b91ac3SNadav Rotem  br i1 %cmp.zero, label %middle.block, label %vector.body
24a6b91ac3SNadav Rotem
25a6b91ac3SNadav Rotemvector.body:                                      ; preds = %for.body.lr.ph, %vector.body
26a6b91ac3SNadav Rotem  %index = phi i64 [ %index.next, %vector.body ], [ %0, %for.body.lr.ph ]
27a6b91ac3SNadav Rotem  %3 = add i64 %index, 2
2879e6c749SDavid Blaikie  %4 = getelementptr inbounds i32, i32* %B, i64 %3
29a6b91ac3SNadav Rotem  ;CHECK: cost of 0 {{.*}} bitcast
30a6b91ac3SNadav Rotem  %5 = bitcast i32* %4 to <8 x i32>*
316d4fdd6dSNadav Rotem  ;CHECK: cost of 2 {{.*}} load
32a79ac14fSDavid Blaikie  %6 = load <8 x i32>, <8 x i32>* %5, align 4
339bd0dc83SSimon Pilgrim  ;CHECK: cost of 5 {{.*}} mul
34a6b91ac3SNadav Rotem  %7 = mul nsw <8 x i32> %6, <i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5, i32 5>
3579e6c749SDavid Blaikie  %8 = getelementptr inbounds i32, i32* %A, i64 %index
36a6b91ac3SNadav Rotem  %9 = bitcast i32* %8 to <8 x i32>*
376d4fdd6dSNadav Rotem  ;CHECK: cost of 2 {{.*}} load
38a79ac14fSDavid Blaikie  %10 = load <8 x i32>, <8 x i32>* %9, align 4
39c2345cbeSNadav Rotem  ;CHECK: cost of 4 {{.*}} add
40a6b91ac3SNadav Rotem  %11 = add nsw <8 x i32> %10, %7
416d4fdd6dSNadav Rotem  ;CHECK: cost of 2 {{.*}} store
42a6b91ac3SNadav Rotem  store <8 x i32> %11, <8 x i32>* %9, align 4
43a6b91ac3SNadav Rotem  %index.next = add i64 %index, 8
44a6b91ac3SNadav Rotem  %12 = icmp eq i64 %index.next, %end.idx.rnd.down
450a471ea6SNadav Rotem  ;CHECK: cost of 0 {{.*}} br
46a6b91ac3SNadav Rotem  br i1 %12, label %middle.block, label %vector.body
47a6b91ac3SNadav Rotem
48a6b91ac3SNadav Rotemmiddle.block:                                     ; preds = %vector.body, %for.body.lr.ph
49a6b91ac3SNadav Rotem  %cmp.n = icmp eq i64 %end.idx, %end.idx.rnd.down
50a6b91ac3SNadav Rotem  br i1 %cmp.n, label %for.end, label %for.body
51a6b91ac3SNadav Rotem
52a6b91ac3SNadav Rotemfor.body:                                         ; preds = %middle.block, %for.body
53a6b91ac3SNadav Rotem  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ %end.idx.rnd.down, %middle.block ]
54a6b91ac3SNadav Rotem  %13 = add nsw i64 %indvars.iv, 2
5579e6c749SDavid Blaikie  %arrayidx = getelementptr inbounds i32, i32* %B, i64 %13
56a6b91ac3SNadav Rotem  ;CHECK: cost of 1 {{.*}} load
57a79ac14fSDavid Blaikie  %14 = load i32, i32* %arrayidx, align 4
58a6b91ac3SNadav Rotem  ;CHECK: cost of 1 {{.*}} mul
59a6b91ac3SNadav Rotem  %mul = mul nsw i32 %14, 5
6079e6c749SDavid Blaikie  %arrayidx2 = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
61a6b91ac3SNadav Rotem  ;CHECK: cost of 1 {{.*}} load
62a79ac14fSDavid Blaikie  %15 = load i32, i32* %arrayidx2, align 4
63a6b91ac3SNadav Rotem  %add3 = add nsw i32 %15, %mul
64662ece49SManman Ren  store i32 %add3, i32* %arrayidx2, align 4
65a6b91ac3SNadav Rotem  %indvars.iv.next = add i64 %indvars.iv, 1
66a6b91ac3SNadav Rotem  ;CHECK: cost of 0 {{.*}} trunc
67a6b91ac3SNadav Rotem  %16 = trunc i64 %indvars.iv.next to i32
68a6b91ac3SNadav Rotem  %cmp = icmp slt i32 %16, %end
690a471ea6SNadav Rotem  ;CHECK: cost of 0 {{.*}} br
70a6b91ac3SNadav Rotem  br i1 %cmp, label %for.body, label %for.end
71a6b91ac3SNadav Rotem
72a6b91ac3SNadav Rotemfor.end:                                          ; preds = %middle.block, %for.body, %entry
730a471ea6SNadav Rotem  ;CHECK: cost of 0 {{.*}} ret
74a6b91ac3SNadav Rotem  ret i32 undef
75a6b91ac3SNadav Rotem}
76