@@ -96,3 +96,67 @@ loop.3:
9696exit:
9797 ret void
9898}
99+
100+ declare i1 @cond ()
101+
102+ define ptr @test_lcssa_reuse_preserve_lcssa () {
103+ ; CHECK-LABEL: define ptr @test_lcssa_reuse_preserve_lcssa() {
104+ ; CHECK-NEXT: [[ENTRY:.*:]]
105+ ; CHECK-NEXT: br label %[[LOOP_0_HEADER:.*]]
106+ ; CHECK: [[LOOP_0_HEADER]]:
107+ ; CHECK-NEXT: br label %[[LOOP_1:.*]]
108+ ; CHECK: [[LOOP_1]]:
109+ ; CHECK-NEXT: [[IV_1:%.*]] = phi ptr [ null, %[[LOOP_0_HEADER]] ], [ [[IV_1_NEXT:%.*]], %[[LOOP_1]] ]
110+ ; CHECK-NEXT: [[IV_1_NEXT]] = getelementptr i8, ptr [[IV_1]], i64 1
111+ ; CHECK-NEXT: [[EC_1:%.*]] = call i1 @cond()
112+ ; CHECK-NEXT: br i1 [[EC_1]], label %[[THEN:.*]], label %[[LOOP_1]]
113+ ; CHECK: [[THEN]]:
114+ ; CHECK-NEXT: [[IV_1_LCSSA:%.*]] = phi ptr [ [[IV_1]], %[[LOOP_1]] ]
115+ ; CHECK-NEXT: [[C_2:%.*]] = call i1 @cond()
116+ ; CHECK-NEXT: br i1 [[C_2]], label %[[LOOP_2_PREHEADER:.*]], label %[[LOOP_0_LATCH:.*]]
117+ ; CHECK: [[LOOP_2_PREHEADER]]:
118+ ; CHECK-NEXT: [[IV_1_LCSSA_LCSSA:%.*]] = phi ptr [ [[IV_1_LCSSA]], %[[THEN]] ]
119+ ; CHECK-NEXT: [[STRLEN:%.*]] = call i64 @strlen(ptr null)
120+ ; CHECK-NEXT: [[TMP0:%.*]] = getelementptr i8, ptr [[IV_1_LCSSA]], i64 1
121+ ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr i8, ptr [[TMP0]], i64 [[STRLEN]]
122+ ; CHECK-NEXT: br label %[[LOOP_2:.*]]
123+ ; CHECK: [[LOOP_2]]:
124+ ; CHECK-NEXT: [[IV_2:%.*]] = phi ptr [ [[RES:%.*]], %[[LOOP_2]] ], [ [[IV_1_LCSSA_LCSSA]], %[[LOOP_2_PREHEADER]] ]
125+ ; CHECK-NEXT: [[RES]] = getelementptr i8, ptr [[IV_2]], i64 1
126+ ; CHECK-NEXT: [[L:%.*]] = load i8, ptr [[IV_1_LCSSA_LCSSA]], align 1
127+ ; CHECK-NEXT: [[EC_2:%.*]] = icmp eq i8 [[L]], 0
128+ ; CHECK-NEXT: br i1 true, label %[[EXIT:.*]], label %[[LOOP_2]]
129+ ; CHECK: [[LOOP_0_LATCH]]:
130+ ; CHECK-NEXT: br label %[[LOOP_0_HEADER]]
131+ ; CHECK: [[EXIT]]:
132+ ; CHECK-NEXT: ret ptr [[SCEVGEP]]
133+ ;
134+ entry:
135+ br label %loop.0.header
136+
137+ loop.0 .header:
138+ br label %loop.1
139+
140+ loop.1 :
141+ %iv.1 = phi ptr [ null , %loop.0.header ], [ %iv.1.next , %loop.1 ]
142+ %iv.1.next = getelementptr i8 , ptr %iv.1 , i64 1
143+ %ec.1 = call i1 @cond ()
144+ br i1 %ec.1 , label %then , label %loop.1
145+
146+ then:
147+ %c.2 = call i1 @cond ()
148+ br i1 %c.2 , label %loop.2 , label %loop.0.latch
149+
150+ loop.2 :
151+ %iv.2 = phi ptr [ %res , %loop.2 ], [ %iv.1 , %then ]
152+ %res = getelementptr i8 , ptr %iv.2 , i64 1
153+ %l = load i8 , ptr %iv.1 , align 1
154+ %ec.2 = icmp eq i8 %l , 0
155+ br i1 %ec.2 , label %exit , label %loop.2
156+
157+ loop.0 .latch:
158+ br label %loop.0.header
159+
160+ exit:
161+ ret ptr %res
162+ }
0 commit comments