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