1 ; RUN: opt -S -passes=jump-threading %s | FileCheck %s
2 ; When simplify a branch based on LVI predicates, we should replace the
3 ; comparison itself with a constant (when possible) in case it's otherwise used.
5 define i32 @test(ptr %p) {
8 ; CHECK-NEXT: br i1 %cmp, label %exit2, label %exit1
11 %cmp = icmp eq ptr %p, null
12 br i1 %cmp, label %is_null, label %not_null
14 %cmp2 = icmp ne ptr %p, null
15 br i1 %cmp2, label %exit1, label %exit2
17 %cmp3 = icmp ne ptr %p, null
18 br i1 %cmp3, label %exit1, label %exit2
27 ; It would not be legal to replace %cmp2 (well, in this case it actually is,
28 ; but that's a CSE problem, not a LVI/jump threading problem)
29 define i32 @test_negative(ptr %p) {
33 ; CHECK-NEXT: br i1 %cmp, label %exit2, label %exit1
36 %cmp2 = icmp ne ptr %p, null
37 call void @use(i1 %cmp2)
38 %cmp = icmp eq ptr %p, null
39 br i1 %cmp, label %is_null, label %not_null
41 br i1 %cmp2, label %exit1, label %exit2
43 br i1 %cmp2, label %exit1, label %exit2
50 ; In this case, we can remove cmp2 because it's otherwise unused
51 define i32 @test2(ptr %p) {
55 ; CHECK-NEXT: br i1 %cmp, label %exit2, label %exit1
58 %cmp2 = icmp ne ptr %p, null
59 %cmp = icmp eq ptr %p, null
60 br i1 %cmp, label %is_null, label %not_null
62 br i1 %cmp2, label %exit1, label %exit2
64 br i1 %cmp2, label %exit1, label %exit2