blob: 1ee9bb409d917ed47b612d427f69511271201995 [file] [log] [blame]
John Bauman66b8ab22014-05-06 15:57:45 -04001; RUN: opt -loop-reduce -S < %s | FileCheck %s
2;
3; Test LSR's intelligence regarding phi reuse.
4; Verify that scaled GEPs are not reused. rdar://5064068
5
6target triple = "x86-apple-darwin"
7
8; CHECK: @test
9; multiplies are hoisted out of the loop
10; CHECK: while.body.lr.ph:
11; CHECK: mul i64
12; CHECK: mul i64
13; GEPs are ugly
14; CHECK: while.body:
15; CHECK: phi
16; CHECK: phi
17; CHECK: phi
18; CHECK: phi
19; CHECK-NOT: phi
20; CHECK: bitcast float* {{.*}} to i8*
21; CHECK: bitcast float* {{.*}} to i8*
22; CHECK: getelementptr i8*
23; CHECK: getelementptr i8*
24
25define float @test(float* nocapture %A, float* nocapture %B, i32 %N, i32 %IA, i32 %IB) nounwind uwtable readonly ssp {
26entry:
27 %cmp1 = icmp sgt i32 %N, 0
28 br i1 %cmp1, label %while.body.lr.ph, label %while.end
29
30while.body.lr.ph: ; preds = %entry
31 %idx.ext = sext i32 %IA to i64
32 %idx.ext2 = sext i32 %IB to i64
33 br label %while.body
34
35while.body: ; preds = %while.body.lr.ph, %while.body
36 %A.addr.05 = phi float* [ %A, %while.body.lr.ph ], [ %add.ptr, %while.body ]
37 %B.addr.04 = phi float* [ %B, %while.body.lr.ph ], [ %add.ptr3, %while.body ]
38 %N.addr.03 = phi i32 [ %N, %while.body.lr.ph ], [ %sub, %while.body ]
39 %Sum0.02 = phi float [ 0.000000e+00, %while.body.lr.ph ], [ %add, %while.body ]
40 %0 = load float* %A.addr.05, align 4
41 %1 = load float* %B.addr.04, align 4
42 %mul = fmul float %0, %1
43 %add = fadd float %Sum0.02, %mul
44 %add.ptr = getelementptr inbounds float* %A.addr.05, i64 %idx.ext
45 %add.ptr3 = getelementptr inbounds float* %B.addr.04, i64 %idx.ext2
46 %sub = add nsw i32 %N.addr.03, -1
47 %cmp = icmp sgt i32 %sub, 0
48 br i1 %cmp, label %while.body, label %while.end
49
50while.end: ; preds = %while.body, %entry
51 %Sum0.0.lcssa = phi float [ 0.000000e+00, %entry ], [ %add, %while.body ]
52 ret float %Sum0.0.lcssa
53}