1; RUN: opt -S -loop-reduce < %s | FileCheck %s
2; Scaling factor in addressing mode are costly.
3; Make loop-reduce prefer unscaled accesses.
4; <rdar://problem/13806271>
5target 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-n32:64-S128"
6target triple = "arm64-apple-ios7.0.0"
7
8; Function Attrs: nounwind ssp
9define void @mulDouble(double* nocapture %a, double* nocapture %b, double* nocapture %c) {
10; CHECK: @mulDouble
11entry:
12  br label %for.body
13
14for.body:                                         ; preds = %for.body, %entry
15; CHECK: [[IV:%[^ ]+]] = phi i64 [ [[IVNEXT:%[^,]+]], %for.body ], [ 0, %entry ]
16; Only one induction variable should have been generated.
17; CHECK-NOT: phi
18  %indvars.iv = phi i64 [ 1, %entry ], [ %indvars.iv.next, %for.body ]
19  %tmp = add nsw i64 %indvars.iv, -1
20  %arrayidx = getelementptr inbounds double, double* %b, i64 %tmp
21  %tmp1 = load double, double* %arrayidx, align 8
22; The induction variable should carry the scaling factor: 1 * 8 = 8.
23; CHECK: [[IVNEXT]] = add nuw nsw i64 [[IV]], 8
24  %indvars.iv.next = add i64 %indvars.iv, 1
25  %arrayidx2 = getelementptr inbounds double, double* %c, i64 %indvars.iv.next
26  %tmp2 = load double, double* %arrayidx2, align 8
27  %mul = fmul double %tmp1, %tmp2
28  %arrayidx4 = getelementptr inbounds double, double* %a, i64 %indvars.iv
29  store double %mul, double* %arrayidx4, align 8
30  %lftr.wideiv = trunc i64 %indvars.iv.next to i32
31; Comparison should be 19 * 8 = 152.
32; CHECK: icmp eq i32 {{%[^,]+}}, 152
33  %exitcond = icmp eq i32 %lftr.wideiv, 20
34  br i1 %exitcond, label %for.end, label %for.body
35
36for.end:                                          ; preds = %for.body
37  ret void
38}
39