1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -aa-pipeline=basic-aa -passes='loop-distribute' -enable-loop-distribute -S %s | FileCheck %s
4 ; Testcases inspired by PR50296, PR50288.
6 define void @phi_load_store_distribute(i1 %c, ptr %A, ptr %B, ptr %C) {
7 ; CHECK-LABEL: @phi_load_store_distribute(
9 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
11 ; CHECK-NEXT: [[IV:%.*]] = phi i16 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[IF_END:%.*]] ]
12 ; CHECK-NEXT: [[LV:%.*]] = load i16, ptr [[A:%.*]], align 1
13 ; CHECK-NEXT: store i16 [[LV]], ptr [[A]], align 1
14 ; CHECK-NEXT: br i1 [[C:%.*]], label [[IF_THEN:%.*]], label [[IF_END]]
16 ; CHECK-NEXT: [[LV2:%.*]] = load i16, ptr [[A]], align 1
17 ; CHECK-NEXT: br label [[IF_END]]
19 ; CHECK-NEXT: [[C_SINK:%.*]] = phi ptr [ [[B:%.*]], [[IF_THEN]] ], [ [[C:%.*]], [[FOR_BODY]] ]
20 ; CHECK-NEXT: [[LV3:%.*]] = load i16, ptr [[C_SINK]], align 2
21 ; CHECK-NEXT: [[ADD:%.*]] = add i16 [[LV3]], 10
22 ; CHECK-NEXT: store i16 [[ADD]], ptr [[C_SINK]], align 1
23 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i16 [[IV]], 1
24 ; CHECK-NEXT: [[TOBOOL_NOT:%.*]] = icmp eq i16 [[IV_NEXT]], 1000
25 ; CHECK-NEXT: br i1 [[TOBOOL_NOT]], label [[FOR_END_LOOPEXIT:%.*]], label [[FOR_BODY]]
26 ; CHECK: for.end.loopexit:
27 ; CHECK-NEXT: ret void
32 for.body: ; preds = %if.end, %entry
33 %iv = phi i16 [ 0, %entry ], [ %iv.next, %if.end ]
34 %lv = load i16, ptr %A, align 1
35 store i16 %lv, ptr %A, align 1
36 br i1 %c, label %if.then, label %if.end
38 if.then: ; preds = %for.body
39 %lv2 = load i16, ptr %A, align 1
42 if.end: ; preds = %if.then, %for.body
43 %c.sink = phi ptr [ %B, %if.then ], [ %C, %for.body ]
44 %lv3 = load i16, ptr %c.sink
45 %add = add i16 %lv3, 10
46 store i16 %add, ptr %c.sink, align 1
47 %iv.next = add nuw nsw i16 %iv, 1
48 %tobool.not = icmp eq i16 %iv.next, 1000
49 br i1 %tobool.not, label %for.end.loopexit, label %for.body
51 for.end.loopexit: ; preds = %if.end
55 define void @phi_load_distribute(i1 %c, ptr %A, ptr %B, ptr %C) {
56 ; CHECK-LABEL: @phi_load_distribute(
58 ; CHECK: for.end.loopexit:
59 ; CHECK-NEXT: ret void
64 for.body: ; preds = %if.end, %entry
65 %iv = phi i16 [ 0, %entry ], [ %iv.next, %if.end ]
66 %lv = load i16, ptr %A, align 1
67 store i16 %lv, ptr %A, align 1
68 br i1 %c, label %if.then, label %if.end
70 if.then: ; preds = %for.body
71 %lv2 = load i16, ptr %A, align 1
74 if.end: ; preds = %if.then, %for.body
75 %c.sink = phi ptr [ %B, %if.then ], [ %C, %for.body ]
76 %lv3 = load i16, ptr %c.sink
77 %iv.next = add nuw nsw i16 %iv, 1
78 %tobool.not = icmp eq i16 %iv.next, 1000
79 br i1 %tobool.not, label %for.end.loopexit, label %for.body
81 for.end.loopexit: ; preds = %if.end