• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt %s -S -simplifycfg | FileCheck %s
2; Check for when one branch implies the value of a successors conditional and
3; it's not simply the same conditional repeated.
4
5define void @test(i32 %length.i, i32 %i) {
6; CHECK-LABEL: @test
7  %iplus1 = add nsw i32 %i, 1
8  %var29 = icmp slt i32 %iplus1, %length.i
9; CHECK: br i1 %var29, label %in_bounds, label %out_of_bounds
10  br i1 %var29, label %next, label %out_of_bounds
11
12next:
13; CHECK-LABEL: in_bounds:
14; CHECK-NEXT: ret void
15  %var30 = icmp slt i32 %i, %length.i
16  br i1 %var30, label %in_bounds, label %out_of_bounds2
17
18in_bounds:
19  ret void
20
21out_of_bounds:
22  call void @foo(i64 0)
23  unreachable
24
25out_of_bounds2:
26  call void @foo(i64 1)
27  unreachable
28}
29
30; If the add is not nsw, it's not safe to use the fact about i+1 to imply the
31; i condition since it could have overflowed.
32define void @test_neg(i32 %length.i, i32 %i) {
33; CHECK-LABEL: @test_neg
34  %iplus1 = add i32 %i, 1
35  %var29 = icmp slt i32 %iplus1, %length.i
36; CHECK: br i1 %var29, label %next, label %out_of_bounds
37  br i1 %var29, label %next, label %out_of_bounds
38
39next:
40  %var30 = icmp slt i32 %i, %length.i
41; CHECK: br i1 %var30, label %in_bounds, label %out_of_bounds2
42  br i1 %var30, label %in_bounds, label %out_of_bounds2
43
44in_bounds:
45  ret void
46
47out_of_bounds:
48  call void @foo(i64 0)
49  unreachable
50
51out_of_bounds2:
52  call void @foo(i64 1)
53  unreachable
54}
55
56
57define void @test2(i32 %length.i, i32 %i) {
58; CHECK-LABEL: @test2
59  %iplus100 = add nsw i32 %i, 100
60  %var29 = icmp slt i32 %iplus100, %length.i
61; CHECK: br i1 %var29, label %in_bounds, label %out_of_bounds
62  br i1 %var29, label %next, label %out_of_bounds
63
64next:
65  %var30 = icmp slt i32 %i, %length.i
66  br i1 %var30, label %in_bounds, label %out_of_bounds2
67
68in_bounds:
69  ret void
70
71out_of_bounds:
72  call void @foo(i64 0)
73  unreachable
74
75out_of_bounds2:
76  call void @foo(i64 1)
77  unreachable
78}
79
80declare void @foo(i64)
81
82