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 -verify-loop-info -verify-dom-info -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 %cond, ptr %A, ptr %B, ptr %C) {
56 ; CHECK-LABEL: @phi_load_distribute(
58 ; CHECK-NEXT: br label [[FOR_BODY_LVER_CHECK:%.*]]
59 ; CHECK: for.body.lver.check:
60 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr i8, ptr [[A:%.*]], i64 2
61 ; CHECK-NEXT: [[SCEVGEP1:%.*]] = getelementptr i8, ptr [[C:%.*]], i64 2
62 ; CHECK-NEXT: [[SCEVGEP2:%.*]] = getelementptr i8, ptr [[B:%.*]], i64 2
63 ; CHECK-NEXT: [[BOUND0:%.*]] = icmp ult ptr [[A]], [[SCEVGEP1]]
64 ; CHECK-NEXT: [[BOUND1:%.*]] = icmp ult ptr [[C]], [[SCEVGEP]]
65 ; CHECK-NEXT: [[FOUND_CONFLICT:%.*]] = and i1 [[BOUND0]], [[BOUND1]]
66 ; CHECK-NEXT: [[BOUND03:%.*]] = icmp ult ptr [[A]], [[SCEVGEP2]]
67 ; CHECK-NEXT: [[BOUND14:%.*]] = icmp ult ptr [[B]], [[SCEVGEP]]
68 ; CHECK-NEXT: [[FOUND_CONFLICT5:%.*]] = and i1 [[BOUND03]], [[BOUND14]]
69 ; CHECK-NEXT: [[CONFLICT_RDX:%.*]] = or i1 [[FOUND_CONFLICT]], [[FOUND_CONFLICT5]]
70 ; CHECK-NEXT: br i1 [[CONFLICT_RDX]], label [[FOR_BODY_PH_LVER_ORIG:%.*]], label [[FOR_BODY_PH_LDIST1:%.*]]
71 ; CHECK: for.body.ph.lver.orig:
72 ; CHECK-NEXT: br label [[FOR_BODY_LVER_ORIG:%.*]]
73 ; CHECK: for.body.lver.orig:
74 ; CHECK-NEXT: [[IV_LVER_ORIG:%.*]] = phi i16 [ 0, [[FOR_BODY_PH_LVER_ORIG]] ], [ [[IV_NEXT_LVER_ORIG:%.*]], [[IF_END_LVER_ORIG:%.*]] ]
75 ; CHECK-NEXT: [[LV_LVER_ORIG:%.*]] = load i16, ptr [[A]], align 1
76 ; CHECK-NEXT: store i16 [[LV_LVER_ORIG]], ptr [[A]], align 1
77 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_THEN_LVER_ORIG:%.*]], label [[IF_END_LVER_ORIG]]
78 ; CHECK: if.then.lver.orig:
79 ; CHECK-NEXT: [[LV2_LVER_ORIG:%.*]] = load i16, ptr [[A]], align 1
80 ; CHECK-NEXT: br label [[IF_END_LVER_ORIG]]
81 ; CHECK: if.end.lver.orig:
82 ; CHECK-NEXT: [[C_SINK_LVER_ORIG:%.*]] = phi ptr [ [[B]], [[IF_THEN_LVER_ORIG]] ], [ [[C]], [[FOR_BODY_LVER_ORIG]] ]
83 ; CHECK-NEXT: [[LV3_LVER_ORIG:%.*]] = load i16, ptr [[C_SINK_LVER_ORIG]], align 2
84 ; CHECK-NEXT: [[IV_NEXT_LVER_ORIG]] = add nuw nsw i16 [[IV_LVER_ORIG]], 1
85 ; CHECK-NEXT: [[TOBOOL_NOT_LVER_ORIG:%.*]] = icmp eq i16 [[IV_NEXT_LVER_ORIG]], 1000
86 ; CHECK-NEXT: br i1 [[TOBOOL_NOT_LVER_ORIG]], label [[FOR_END_LOOPEXIT_LOOPEXIT:%.*]], label [[FOR_BODY_LVER_ORIG]]
87 ; CHECK: for.body.ph.ldist1:
88 ; CHECK-NEXT: br label [[FOR_BODY_LDIST1:%.*]]
89 ; CHECK: for.body.ldist1:
90 ; CHECK-NEXT: [[IV_LDIST1:%.*]] = phi i16 [ 0, [[FOR_BODY_PH_LDIST1]] ], [ [[IV_NEXT_LDIST1:%.*]], [[IF_END_LDIST1:%.*]] ]
91 ; CHECK-NEXT: [[LV_LDIST1:%.*]] = load i16, ptr [[A]], align 1, !alias.scope [[META0:![0-9]+]], !noalias [[META3:![0-9]+]]
92 ; CHECK-NEXT: store i16 [[LV_LDIST1]], ptr [[A]], align 1, !alias.scope [[META0]], !noalias [[META3]]
93 ; CHECK-NEXT: br i1 [[COND]], label [[IF_THEN_LDIST1:%.*]], label [[IF_END_LDIST1]]
94 ; CHECK: if.then.ldist1:
95 ; CHECK-NEXT: [[LV2_LDIST1:%.*]] = load i16, ptr [[A]], align 1, !alias.scope [[META0]], !noalias [[META3]]
96 ; CHECK-NEXT: br label [[IF_END_LDIST1]]
97 ; CHECK: if.end.ldist1:
98 ; CHECK-NEXT: [[IV_NEXT_LDIST1]] = add nuw nsw i16 [[IV_LDIST1]], 1
99 ; CHECK-NEXT: [[TOBOOL_NOT_LDIST1:%.*]] = icmp eq i16 [[IV_NEXT_LDIST1]], 1000
100 ; CHECK-NEXT: br i1 [[TOBOOL_NOT_LDIST1]], label [[FOR_BODY_PH:%.*]], label [[FOR_BODY_LDIST1]]
101 ; CHECK: for.body.ph:
102 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
104 ; CHECK-NEXT: [[IV:%.*]] = phi i16 [ 0, [[FOR_BODY_PH]] ], [ [[IV_NEXT:%.*]], [[IF_END:%.*]] ]
105 ; CHECK-NEXT: br i1 [[COND]], label [[IF_THEN:%.*]], label [[IF_END]]
107 ; CHECK-NEXT: br label [[IF_END]]
109 ; CHECK-NEXT: [[C_SINK:%.*]] = phi ptr [ [[B]], [[IF_THEN]] ], [ [[C]], [[FOR_BODY]] ]
110 ; CHECK-NEXT: [[LV3:%.*]] = load i16, ptr [[C_SINK]], align 2
111 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i16 [[IV]], 1
112 ; CHECK-NEXT: [[TOBOOL_NOT:%.*]] = icmp eq i16 [[IV_NEXT]], 1000
113 ; CHECK-NEXT: br i1 [[TOBOOL_NOT]], label [[FOR_END_LOOPEXIT_LOOPEXIT6:%.*]], label [[FOR_BODY]]
114 ; CHECK: for.end.loopexit.loopexit:
115 ; CHECK-NEXT: br label [[FOR_END_LOOPEXIT:%.*]]
116 ; CHECK: for.end.loopexit.loopexit6:
117 ; CHECK-NEXT: br label [[FOR_END_LOOPEXIT]]
118 ; CHECK: for.end.loopexit:
119 ; CHECK-NEXT: ret void
124 for.body: ; preds = %if.end, %entry
125 %iv = phi i16 [ 0, %entry ], [ %iv.next, %if.end ]
126 %lv = load i16, ptr %A, align 1
127 store i16 %lv, ptr %A, align 1
128 br i1 %cond, label %if.then, label %if.end
130 if.then: ; preds = %for.body
131 %lv2 = load i16, ptr %A, align 1
134 if.end: ; preds = %if.then, %for.body
135 %c.sink = phi ptr [ %B, %if.then ], [ %C, %for.body ]
136 %lv3 = load i16, ptr %c.sink
137 %iv.next = add nuw nsw i16 %iv, 1
138 %tobool.not = icmp eq i16 %iv.next, 1000
139 br i1 %tobool.not, label %for.end.loopexit, label %for.body
141 for.end.loopexit: ; preds = %if.end