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.
5 define void @test(i32 %length.i, i32 %i) {
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
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
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.
32 define 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
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
57 define void @test2(i32 %length.i, i32 %i) {
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
65 %var30 = icmp slt i32 %i, %length.i
66 br i1 %var30, label %in_bounds, label %out_of_bounds2
80 declare void @foo(i64)