[SimplifyCFG] Further improve our ability to remove redundant catchpads
[oota-llvm.git] / test / Transforms / EarlyCSE / conditional.ll
1 ; RUN: opt -early-cse -S < %s | FileCheck %s
2
3 ; Can we CSE a known condition to a constant?
4 define i1 @test(i8* %p) {
5 ; CHECK-LABEL: @test
6 entry:
7   %cnd1 = icmp eq i8* %p, null
8   br i1 %cnd1, label %taken, label %untaken
9
10 taken:
11 ; CHECK-LABEL: taken:
12 ; CHECK-NEXT: ret i1 true
13   %cnd2 = icmp eq i8* %p, null
14   ret i1 %cnd2
15
16 untaken:
17 ; CHECK-LABEL: untaken:
18 ; CHECK-NEXT: ret i1 false
19   %cnd3 = icmp eq i8* %p, null
20   ret i1 %cnd3
21 }
22
23 ; We can CSE the condition, but we *don't* know it's value after the merge
24 define i1 @test_neg1(i8* %p) {
25 ; CHECK-LABEL: @test_neg1
26 entry:
27   %cnd1 = icmp eq i8* %p, null
28   br i1 %cnd1, label %taken, label %untaken
29
30 taken:
31   br label %merge
32
33 untaken:
34   br label %merge
35
36 merge:
37 ; CHECK-LABEL: merge:
38 ; CHECK-NEXT: ret i1 %cnd1
39   %cnd3 = icmp eq i8* %p, null
40   ret i1 %cnd3
41 }
42
43 ; Check specifically for a case where we have a unique predecessor, but
44 ; not a single predecessor.  We can not know the value of the condition here.
45 define i1 @test_neg2(i8* %p) {
46 ; CHECK-LABEL: @test_neg2
47 entry:
48   %cnd1 = icmp eq i8* %p, null
49   br i1 %cnd1, label %merge, label %merge
50
51 merge:
52 ; CHECK-LABEL: merge:
53 ; CHECK-NEXT: ret i1 %cnd1
54   %cnd3 = icmp eq i8* %p, null
55   ret i1 %cnd3
56 }
57
58 ; Replace a use rather than CSE
59 define i1 @test2(i8* %p) {
60 ; CHECK-LABEL: @test2
61 entry:
62   %cnd = icmp eq i8* %p, null
63   br i1 %cnd, label %taken, label %untaken
64
65 taken:
66 ; CHECK-LABEL: taken:
67 ; CHECK-NEXT: ret i1 true
68   ret i1 %cnd
69
70 untaken:
71 ; CHECK-LABEL: untaken:
72 ; CHECK-NEXT: ret i1 false
73   ret i1 %cnd
74 }
75
76 ; Not legal to replace use given it's not dominated by edge
77 define i1 @test2_neg1(i8* %p) {
78 ; CHECK-LABEL: @test2_neg1
79 entry:
80   %cnd1 = icmp eq i8* %p, null
81   br i1 %cnd1, label %taken, label %untaken
82
83 taken:
84   br label %merge
85
86 untaken:
87   br label %merge
88
89 merge:
90 ; CHECK-LABEL: merge:
91 ; CHECK-NEXT: ret i1 %cnd1
92   ret i1 %cnd1
93 }
94
95 ; Another single predecessor test, but for dominated use
96 define i1 @test2_neg2(i8* %p) {
97 ; CHECK-LABEL: @test2_neg2
98 entry:
99   %cnd1 = icmp eq i8* %p, null
100   br i1 %cnd1, label %merge, label %merge
101
102 merge:
103 ; CHECK-LABEL: merge:
104 ; CHECK-NEXT: ret i1 %cnd1
105   ret i1 %cnd1
106 }
107