Skip to content

Commit 5480713

Browse files
committed
Add test that sinks part of the way to the use
Signed-off-by: John Lu <[email protected]>
1 parent e78335e commit 5480713

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

llvm/test/Transforms/Sink/loadsink.ll

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,49 @@ thenB:
150150
mergeC:
151151
ret void
152152
}
153+
154+
; Load can be sunk, but not all the way to the use.
155+
define void @load_can_sink_part_of_the_way(i1 %condA, i1 %condB, i1 %condC, ptr noalias %a, ptr %b) {
156+
; CHECK-LABEL: @load_can_sink_part_of_the_way(
157+
; CHECK-NEXT: entry:
158+
; CHECK-NEXT: br label [[MERGEA:%.*]]
159+
; CHECK: mergeA:
160+
; CHECK-NEXT: br i1 [[CONDA:%.*]], label [[THENA:%.*]], label [[MERGEB:%.*]]
161+
; CHECK: thenA:
162+
; CHECK-NEXT: store i32 0, ptr [[B:%.*]], align 4
163+
; CHECK-NEXT: br label [[MERGEB]]
164+
; CHECK: mergeB:
165+
; CHECK-NEXT: [[VALUE:%.*]] = load i32, ptr [[A:%.*]], align 4
166+
; CHECK-NEXT: br i1 [[CONDB:%.*]], label [[THENB:%.*]], label [[MERGEC:%.*]]
167+
; CHECK: thenB:
168+
; CHECK-NEXT: call void @maywritefunc()
169+
; CHECK-NEXT: br label [[MERGEC]]
170+
; CHECK: mergeC:
171+
; CHECK-NEXT: br i1 [[CONDC:%.*]], label [[THENC:%.*]], label [[MERGED:%.*]]
172+
; CHECK: thenC:
173+
; CHECK-NEXT: store i32 [[VALUE]], ptr [[B]], align 4
174+
; CHECK-NEXT: br label [[MERGEC]]
175+
; CHECK: mergeD:
176+
; CHECK-NEXT: ret void
177+
;
178+
entry:
179+
%value = load i32, ptr %a, align 4
180+
br label %mergeA
181+
mergeA:
182+
br i1 %condA, label %thenA, label %mergeB
183+
thenA:
184+
store i32 0, ptr %b
185+
br label %mergeB
186+
mergeB:
187+
br i1 %condB, label %thenB, label %mergeC
188+
thenB:
189+
call void @maywritefunc()
190+
br label %mergeC
191+
mergeC:
192+
br i1 %condC, label %thenC, label %mergeD
193+
thenC:
194+
store i32 %value, ptr %b
195+
br label %mergeC
196+
mergeD:
197+
ret void
198+
}

0 commit comments

Comments
 (0)