1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2 ; RUN: opt -passes=loop-load-elim -S %s | FileCheck %s
4 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
6 define void @f(ptr %A, ptr %B, ptr %C, i64 %N) {
7 ; CHECK-LABEL: define void @f(
8 ; CHECK-SAME: ptr [[A:%.*]], ptr [[B:%.*]], ptr [[C:%.*]], i64 [[N:%.*]]) {
9 ; CHECK-NEXT: [[FOR_BODY_LVER_CHECK:.*]]:
10 ; CHECK-NEXT: br label %[[FOR_BODY:.*]]
11 ; CHECK: [[FOR_BODY]]:
12 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, %[[FOR_BODY_LVER_CHECK]] ], [ [[INDVARS_IV_NEXT:%.*]], %[[LATCH:.*]] ]
13 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
14 ; CHECK-NEXT: [[AIDX_NEXT:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[INDVARS_IV_NEXT]]
15 ; CHECK-NEXT: [[BIDX:%.*]] = getelementptr inbounds i32, ptr [[B]], i64 [[INDVARS_IV]]
16 ; CHECK-NEXT: [[CIDX:%.*]] = getelementptr inbounds i32, ptr [[C]], i64 [[INDVARS_IV]]
17 ; CHECK-NEXT: [[AIDX:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[INDVARS_IV]]
18 ; CHECK-NEXT: [[B:%.*]] = load i32, ptr [[BIDX]], align 4
19 ; CHECK-NEXT: [[UNCOUNTABLE_C:%.*]] = icmp eq i32 [[B]], 10
20 ; CHECK-NEXT: br i1 [[UNCOUNTABLE_C]], label %[[LATCH]], label %[[FOR_END:.*]]
22 ; CHECK-NEXT: [[A_P1:%.*]] = add i32 [[B]], 2
23 ; CHECK-NEXT: store i32 [[A_P1]], ptr [[AIDX_NEXT]], align 4
24 ; CHECK-NEXT: [[A:%.*]] = load i32, ptr [[AIDX]], align 1
25 ; CHECK-NEXT: [[C:%.*]] = mul i32 [[A]], 2
26 ; CHECK-NEXT: store i32 [[C]], ptr [[CIDX]], align 4
27 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], [[N]]
28 ; CHECK-NEXT: br i1 [[EXITCOND]], label %[[FOR_END]], label %[[FOR_BODY]]
30 ; CHECK-NEXT: ret void
35 for.body: ; preds = %for.body, %entry
36 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %latch ]
37 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
39 %Aidx_next = getelementptr inbounds i32, ptr %A, i64 %indvars.iv.next
40 %Bidx = getelementptr inbounds i32, ptr %B, i64 %indvars.iv
41 %Cidx = getelementptr inbounds i32, ptr %C, i64 %indvars.iv
42 %Aidx = getelementptr inbounds i32, ptr %A, i64 %indvars.iv
44 %b = load i32, ptr %Bidx, align 4
45 %uncountable.c = icmp eq i32 %b, 10
46 br i1 %uncountable.c, label %latch, label %for.end
50 store i32 %a_p1, ptr %Aidx_next, align 4
52 %a = load i32, ptr %Aidx, align 1
54 store i32 %c, ptr %Cidx, align 4
56 %exitcond = icmp eq i64 %indvars.iv.next, %N
57 br i1 %exitcond, label %for.end, label %for.body
59 for.end: ; preds = %for.body