1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2 ; RUN: opt -loop-reduce -S < %s | FileCheck %s
4 ; Test LSR's intelligence regarding phi reuse.
5 ; Verify that scaled GEPs are not reused. rdar://5064068
7 target triple = "x86_64-apple-darwin"
9 ; Provide legal integer types.
10 target datalayout = "n8:16:32:64"
13 define float @test(ptr nocapture %A, ptr nocapture %B, i32 %N, i32 %IA, i32 %IB) nounwind uwtable readonly ssp {
14 ; CHECK-LABEL: define float @test
15 ; CHECK-SAME: (ptr captures(none) [[A:%.*]], ptr captures(none) [[B:%.*]], i32 [[N:%.*]], i32 [[IA:%.*]], i32 [[IB:%.*]]) #[[ATTR0:[0-9]+]] {
17 ; CHECK-NEXT: [[CMP1:%.*]] = icmp sgt i32 [[N]], 0
18 ; CHECK-NEXT: br i1 [[CMP1]], label [[WHILE_BODY_LR_PH:%.*]], label [[WHILE_END:%.*]]
19 ; CHECK: while.body.lr.ph:
20 ; CHECK-NEXT: [[IDX_EXT:%.*]] = sext i32 [[IA]] to i64
21 ; CHECK-NEXT: [[IDX_EXT2:%.*]] = sext i32 [[IB]] to i64
22 ; CHECK-NEXT: [[TMP0:%.*]] = shl nsw i64 [[IDX_EXT]], 2
23 ; CHECK-NEXT: [[TMP1:%.*]] = shl nsw i64 [[IDX_EXT2]], 2
24 ; CHECK-NEXT: br label [[WHILE_BODY:%.*]]
26 ; CHECK-NEXT: [[LSR_IV1:%.*]] = phi ptr [ [[SCEVGEP2:%.*]], [[WHILE_BODY]] ], [ [[B]], [[WHILE_BODY_LR_PH]] ]
27 ; CHECK-NEXT: [[LSR_IV:%.*]] = phi ptr [ [[SCEVGEP:%.*]], [[WHILE_BODY]] ], [ [[A]], [[WHILE_BODY_LR_PH]] ]
28 ; CHECK-NEXT: [[N_ADDR_03:%.*]] = phi i32 [ [[N]], [[WHILE_BODY_LR_PH]] ], [ [[SUB:%.*]], [[WHILE_BODY]] ]
29 ; CHECK-NEXT: [[SUM0_02:%.*]] = phi float [ 0.000000e+00, [[WHILE_BODY_LR_PH]] ], [ [[ADD:%.*]], [[WHILE_BODY]] ]
30 ; CHECK-NEXT: [[TMP2:%.*]] = load float, ptr [[LSR_IV]], align 4
31 ; CHECK-NEXT: [[TMP3:%.*]] = load float, ptr [[LSR_IV1]], align 4
32 ; CHECK-NEXT: [[MUL:%.*]] = fmul float [[TMP2]], [[TMP3]]
33 ; CHECK-NEXT: [[ADD]] = fadd float [[SUM0_02]], [[MUL]]
34 ; CHECK-NEXT: [[SUB]] = add nsw i32 [[N_ADDR_03]], -1
35 ; CHECK-NEXT: [[SCEVGEP]] = getelementptr i8, ptr [[LSR_IV]], i64 [[TMP0]]
36 ; CHECK-NEXT: [[SCEVGEP2]] = getelementptr i8, ptr [[LSR_IV1]], i64 [[TMP1]]
37 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[SUB]], 0
38 ; CHECK-NEXT: br i1 [[CMP]], label [[WHILE_BODY]], label [[WHILE_END_LOOPEXIT:%.*]]
39 ; CHECK: while.end.loopexit:
40 ; CHECK-NEXT: br label [[WHILE_END]]
42 ; CHECK-NEXT: [[SUM0_0_LCSSA:%.*]] = phi float [ 0.000000e+00, [[ENTRY:%.*]] ], [ [[ADD]], [[WHILE_END_LOOPEXIT]] ]
43 ; CHECK-NEXT: ret float [[SUM0_0_LCSSA]]
46 %cmp1 = icmp sgt i32 %N, 0
47 br i1 %cmp1, label %while.body.lr.ph, label %while.end
49 while.body.lr.ph: ; preds = %entry
50 %idx.ext = sext i32 %IA to i64
51 %idx.ext2 = sext i32 %IB to i64
54 while.body: ; preds = %while.body.lr.ph, %while.body
55 %A.addr.05 = phi ptr [ %A, %while.body.lr.ph ], [ %add.ptr, %while.body ]
56 %B.addr.04 = phi ptr [ %B, %while.body.lr.ph ], [ %add.ptr3, %while.body ]
57 %N.addr.03 = phi i32 [ %N, %while.body.lr.ph ], [ %sub, %while.body ]
58 %Sum0.02 = phi float [ 0.000000e+00, %while.body.lr.ph ], [ %add, %while.body ]
59 %0 = load float, ptr %A.addr.05, align 4
60 %1 = load float, ptr %B.addr.04, align 4
61 %mul = fmul float %0, %1
62 %add = fadd float %Sum0.02, %mul
63 %add.ptr = getelementptr inbounds float, ptr %A.addr.05, i64 %idx.ext
64 %add.ptr3 = getelementptr inbounds float, ptr %B.addr.04, i64 %idx.ext2
65 %sub = add nsw i32 %N.addr.03, -1
66 %cmp = icmp sgt i32 %sub, 0
67 br i1 %cmp, label %while.body, label %while.end
69 while.end: ; preds = %while.body, %entry
70 %Sum0.0.lcssa = phi float [ 0.000000e+00, %entry ], [ %add, %while.body ]
71 ret float %Sum0.0.lcssa