1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -jump-threading -S < %s | FileCheck %s
3
4declare i32 @f1()
5declare i32 @f2()
6declare void @f3()
7
8; trunc(and) should be simplified
9define i32 @test(i1 %cond0) {
10; CHECK-LABEL: @test(
11; CHECK-NEXT:    br i1 [[COND0:%.*]], label [[T1:%.*]], label [[F1:%.*]]
12; CHECK:       T1:
13; CHECK-NEXT:    [[V1:%.*]] = call i32 @f1()
14; CHECK-NEXT:    br label [[F2:%.*]]
15; CHECK:       F1:
16; CHECK-NEXT:    [[V2:%.*]] = call i32 @f2()
17; CHECK-NEXT:    br label [[F2]]
18; CHECK:       F2:
19; CHECK-NEXT:    [[A:%.*]] = phi i32 [ 10, [[T1]] ], [ 0, [[F1]] ]
20; CHECK-NEXT:    [[B:%.*]] = phi i32 [ [[V1]], [[T1]] ], [ [[V2]], [[F1]] ]
21; CHECK-NEXT:    [[AND:%.*]] = and i32 [[A]], 1
22; CHECK-NEXT:    ret i32 [[B]]
23;
24  br i1 %cond0, label %T1, label %F1
25T1:
26  %v1 = call i32 @f1()
27  br label %Merge
28
29F1:
30  %v2 = call i32 @f2()
31  br label %Merge
32
33Merge:
34  %A = phi i32 [10, %T1], [0, %F1]
35  %B = phi i32 [%v1, %T1], [%v2, %F1]
36  %And = and i32 %A, 1
37  %cond = trunc i32 %And to i1
38  br i1 %cond, label %T2, label %F2
39
40T2:
41  call void @f3()
42  ret i32 %B
43
44F2:
45  ret i32 %B
46}
47
48; trunc(select) should be simplified
49define i32 @test2(i1 %cond0) {
50; CHECK-LABEL: @test2(
51; CHECK-NEXT:    br i1 [[COND0:%.*]], label [[T1:%.*]], label [[F1:%.*]]
52; CHECK:       T1:
53; CHECK-NEXT:    [[V1:%.*]] = call i32 @f1()
54; CHECK-NEXT:    br label [[F2:%.*]]
55; CHECK:       F1:
56; CHECK-NEXT:    [[V2:%.*]] = call i32 @f2()
57; CHECK-NEXT:    br label [[F2]]
58; CHECK:       F2:
59; CHECK-NEXT:    [[A:%.*]] = phi i1 [ true, [[T1]] ], [ false, [[F1]] ]
60; CHECK-NEXT:    [[B:%.*]] = phi i32 [ [[V1]], [[T1]] ], [ [[V2]], [[F1]] ]
61; CHECK-NEXT:    [[A2:%.*]] = xor i1 [[A]], true
62; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[A2]], i32 10, i32 0
63; CHECK-NEXT:    ret i32 [[B]]
64;
65  br i1 %cond0, label %T1, label %F1
66T1:
67  %v1 = call i32 @f1()
68  br label %Merge
69
70F1:
71  %v2 = call i32 @f2()
72  br label %Merge
73
74Merge:
75  %A = phi i1 [1, %T1], [0, %F1]
76  %B = phi i32 [%v1, %T1], [%v2, %F1]
77  %A2 = xor i1 %A, 1
78  %sel = select i1 %A2, i32 10, i32 0
79  %cond = trunc i32 %sel to i1
80  br i1 %cond, label %T2, label %F2
81
82T2:
83  call void @f3()
84  ret i32 %B
85
86F2:
87  ret i32 %B
88}
89
90