implied-cond.ll
3.59 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
; RUN: opt -jump-threading -S < %s | FileCheck %s
declare void @side_effect(i32)
define void @test0(i32 %i, i32 %len) {
; CHECK-LABEL: @test0(
entry:
call void @side_effect(i32 0)
%i.inc = add nuw i32 %i, 1
%c0 = icmp ult i32 %i.inc, %len
br i1 %c0, label %left, label %right
left:
; CHECK: entry:
; CHECK: br i1 %c0, label %left0, label %right
; CHECK: left0:
; CHECK: call void @side_effect
; CHECK-NOT: br i1 %c1
; CHECK: call void @side_effect
call void @side_effect(i32 0)
%c1 = icmp ult i32 %i, %len
br i1 %c1, label %left0, label %right
left0:
call void @side_effect(i32 0)
ret void
right:
%t = phi i32 [ 1, %left ], [ 2, %entry ]
call void @side_effect(i32 %t)
ret void
}
define void @test1(i32 %i, i32 %len) {
; CHECK-LABEL: @test1(
entry:
call void @side_effect(i32 0)
%i.inc = add nsw i32 %i, 1
%c0 = icmp slt i32 %i.inc, %len
br i1 %c0, label %left, label %right
left:
; CHECK: entry:
; CHECK: br i1 %c0, label %left0, label %right
; CHECK: left0:
; CHECK: call void @side_effect
; CHECK-NOT: br i1 %c1
; CHECK: call void @side_effect
call void @side_effect(i32 0)
%c1 = icmp slt i32 %i, %len
br i1 %c1, label %left0, label %right
left0:
call void @side_effect(i32 0)
ret void
right:
%t = phi i32 [ 1, %left ], [ 2, %entry ]
call void @side_effect(i32 %t)
ret void
}
define void @test2(i32 %i, i32 %len, i1* %c.ptr) {
; CHECK-LABEL: @test2(
; CHECK: entry:
; CHECK: br i1 %c0, label %cont, label %right
; CHECK: cont:
; CHECK: br i1 %c, label %left0, label %right
; CHECK: left0:
; CHECK: call void @side_effect(i32 0)
; CHECK: call void @side_effect(i32 0)
entry:
call void @side_effect(i32 0)
%i.inc = add nsw i32 %i, 1
%c0 = icmp slt i32 %i.inc, %len
br i1 %c0, label %cont, label %right
cont:
%c = load i1, i1* %c.ptr
br i1 %c, label %left, label %right
left:
call void @side_effect(i32 0)
%c1 = icmp slt i32 %i, %len
br i1 %c1, label %left0, label %right
left0:
call void @side_effect(i32 0)
ret void
right:
%t = phi i32 [ 1, %left ], [ 2, %entry ], [ 3, %cont ]
call void @side_effect(i32 %t)
ret void
}
; A s<= B implies A s> B is false.
; CHECK-LABEL: @test3(
; CHECK: entry:
; CHECK: br i1 %cmp, label %if.end, label %if.end3
; CHECK-NOT: br i1 %cmp1, label %if.then2, label %if.end
; CHECK-NOT: call void @side_effect(i32 0)
; CHECK: br label %if.end3
; CHECK: ret void
define void @test3(i32 %a, i32 %b) {
entry:
%cmp = icmp sle i32 %a, %b
br i1 %cmp, label %if.then, label %if.end3
if.then:
%cmp1 = icmp sgt i32 %a, %b
br i1 %cmp1, label %if.then2, label %if.end
if.then2:
call void @side_effect(i32 0)
br label %if.end
if.end:
br label %if.end3
if.end3:
ret void
}
declare void @is(i1)
; If A >=s B is false then A <=s B is implied true.
; CHECK-LABEL: @test_sge_sle
; CHECK: call void @is(i1 true)
; CHECK-NOT: call void @is(i1 false)
define void @test_sge_sle(i32 %a, i32 %b) {
%cmp1 = icmp sge i32 %a, %b
br i1 %cmp1, label %untaken, label %taken
taken:
%cmp2 = icmp sle i32 %a, %b
br i1 %cmp2, label %istrue, label %isfalse
istrue:
call void @is(i1 true)
ret void
isfalse:
call void @is(i1 false)
ret void
untaken:
ret void
}
; If A <=s B is false then A <=s B is implied false.
; CHECK-LABEL: @test_sle_sle
; CHECK-NOT: call void @is(i1 true)
; CHECK: call void @is(i1 false)
define void @test_sle_sle(i32 %a, i32 %b) {
%cmp1 = icmp sle i32 %a, %b
br i1 %cmp1, label %untaken, label %taken
taken:
%cmp2 = icmp sle i32 %a, %b
br i1 %cmp2, label %istrue, label %isfalse
istrue:
call void @is(i1 true)
ret void
isfalse:
call void @is(i1 false)
ret void
untaken:
ret void
}