1 ; RUN: opt -early-cse -S < %s | FileCheck %s
3 ; Can we CSE a known condition to a constant?
4 define i1 @test(i8* %p) {
7 %cnd1 = icmp eq i8* %p, null
8 br i1 %cnd1, label %taken, label %untaken
12 ; CHECK-NEXT: ret i1 true
13 %cnd2 = icmp eq i8* %p, null
17 ; CHECK-LABEL: untaken:
18 ; CHECK-NEXT: ret i1 false
19 %cnd3 = icmp eq i8* %p, null
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
27 %cnd1 = icmp eq i8* %p, null
28 br i1 %cnd1, label %taken, label %untaken
38 ; CHECK-NEXT: ret i1 %cnd1
39 %cnd3 = icmp eq i8* %p, null
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
48 %cnd1 = icmp eq i8* %p, null
49 br i1 %cnd1, label %merge, label %merge
53 ; CHECK-NEXT: ret i1 %cnd1
54 %cnd3 = icmp eq i8* %p, null
58 ; Replace a use rather than CSE
59 define i1 @test2(i8* %p) {
62 %cnd = icmp eq i8* %p, null
63 br i1 %cnd, label %taken, label %untaken
67 ; CHECK-NEXT: ret i1 true
71 ; CHECK-LABEL: untaken:
72 ; CHECK-NEXT: ret i1 false
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
80 %cnd1 = icmp eq i8* %p, null
81 br i1 %cnd1, label %taken, label %untaken
91 ; CHECK-NEXT: ret i1 %cnd1
95 ; Another single predecessor test, but for dominated use
96 define i1 @test2_neg2(i8* %p) {
97 ; CHECK-LABEL: @test2_neg2
99 %cnd1 = icmp eq i8* %p, null
100 br i1 %cnd1, label %merge, label %merge
103 ; CHECK-LABEL: merge:
104 ; CHECK-NEXT: ret i1 %cnd1