1 ; RUN: opt -early-cse -earlycse-debug-hash -S < %s | FileCheck %s
2 ; RUN: opt -basic-aa -early-cse-memssa -S < %s | FileCheck %s
4 ; Can we CSE a known condition to a constant?
5 define i1 @test(i8* %p) {
8 %cnd1 = icmp eq i8* %p, null
9 br i1 %cnd1, label %taken, label %untaken
13 ; CHECK-NEXT: ret i1 true
14 %cnd2 = icmp eq i8* %p, null
18 ; CHECK-LABEL: untaken:
19 ; CHECK-NEXT: ret i1 false
20 %cnd3 = icmp eq i8* %p, null
24 ; We can CSE the condition, but we *don't* know it's value after the merge
25 define i1 @test_neg1(i8* %p) {
26 ; CHECK-LABEL: @test_neg1
28 %cnd1 = icmp eq i8* %p, null
29 br i1 %cnd1, label %taken, label %untaken
39 ; CHECK-NEXT: ret i1 %cnd1
40 %cnd3 = icmp eq i8* %p, null
44 ; Check specifically for a case where we have a unique predecessor, but
45 ; not a single predecessor. We can not know the value of the condition here.
46 define i1 @test_neg2(i8* %p) {
47 ; CHECK-LABEL: @test_neg2
49 %cnd1 = icmp eq i8* %p, null
50 br i1 %cnd1, label %merge, label %merge
54 ; CHECK-NEXT: ret i1 %cnd1
55 %cnd3 = icmp eq i8* %p, null
59 ; Replace a use rather than CSE
60 define i1 @test2(i8* %p) {
63 %cnd = icmp eq i8* %p, null
64 br i1 %cnd, label %taken, label %untaken
68 ; CHECK-NEXT: ret i1 true
72 ; CHECK-LABEL: untaken:
73 ; CHECK-NEXT: ret i1 false
77 ; Not legal to replace use given it's not dominated by edge
78 define i1 @test2_neg1(i8* %p) {
79 ; CHECK-LABEL: @test2_neg1
81 %cnd1 = icmp eq i8* %p, null
82 br i1 %cnd1, label %taken, label %untaken
92 ; CHECK-NEXT: ret i1 %cnd1
96 ; Another single predecessor test, but for dominated use
97 define i1 @test2_neg2(i8* %p) {
98 ; CHECK-LABEL: @test2_neg2
100 %cnd1 = icmp eq i8* %p, null
101 br i1 %cnd1, label %merge, label %merge
104 ; CHECK-LABEL: merge:
105 ; CHECK-NEXT: ret i1 %cnd1