-
Notifications
You must be signed in to change notification settings - Fork 395
/
loop-deletion.ll
54 lines (46 loc) · 1.46 KB
/
loop-deletion.ll
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
; RUN: opt -passes=loop-deletion -S < %s | FileCheck %s
;------------------------------------------------------------------------------
; CASE 1: A loop that's never executed
;------------------------------------------------------------------------------
define void @bar(i64 %n, i64 %m) nounwind {
; CHECK-LABEL: bar
; CHECK-LABEL: entry:
; CHECK-NEXT: br i1 true, label %return, label %header_block.preheader
; CHECK-NOT: header_block:
; CHECK-NOT: latch_block:
entry:
br i1 true, label %return, label %header_block
header_block:
%x.0 = phi i64 [ 0, %entry ], [ %t0, %latch_block ]
%t0 = add i64 %x.0, 1
%t1 = icmp slt i64 %x.0, %n
%t3 = icmp sgt i64 %x.0, %m
%t4 = and i1 %t1, %t3
br label %latch_block
latch_block:
br i1 true, label %header_block, label %return
return:
ret void
}
;------------------------------------------------------------------------------
; CASE 2: A finite loop that does not affect the return value
;------------------------------------------------------------------------------
define void @foo(i64 %n, i64 %m) nounwind {
; CHECK-LABEL: foo
; CHECK-LABEL: entry:
; CHECK: br label %return
; CHECK-LABEL: return:
; CHECK: ret void
entry:
br label %header_block
header_block:
%x.0 = phi i64 [ 0, %entry ], [ %t0, %latch_block ]
%t0 = add i64 %x.0, 1
%t1 = icmp slt i64 %x.0, %n
br i1 %t1, label %latch_block, label %return
latch_block:
%t2 = icmp slt i64 %x.0, %m
br i1 %t1, label %header_block, label %return
return:
ret void
}