1 ; RUN: opt < %s -gvn -enable-pre -S | FileCheck %s
3 declare void @may_exit() nounwind
5 declare void @may_exit_1(i32) nounwind
7 define i32 @main(i32 %p, i32 %q) {
12 %cmp = icmp eq i32 %p, %q
13 br i1 %cmp, label %block2, label %block3
21 ; CHECK: %.pre = add i32 %p, 1
22 ; CHECK-NEXT: br label %block4
27 ; CHECK: %b.pre-phi = phi i32 [ %.pre, %block3 ], [ %a, %block2 ]
28 ; CHECK-NEXT: ret i32 %b.pre-phi
31 ; Don't PRE across implicit control flow.
32 define i32 @test2(i32 %p, i32 %q) {
38 %cmp = icmp eq i32 %p, %q
39 br i1 %cmp, label %block2, label %block3
49 ; CHECK-NEXT: call void @may_exit(
50 ; CHECK-NEXT: %b = sdiv
51 ; CHECK-NEXT: ret i32 %b
54 call void @may_exit() nounwind
59 ; Don't PRE across implicit control flow.
60 define i32 @test3(i32 %p, i32 %q, i1 %r) {
66 br i1 %r, label %block2, label %block3
79 ; CHECK-NEXT: call void @may_exit_1(
80 ; CHECK-NEXT: %b = sdiv
81 ; CHECK-NEXT: ret i32 %b
83 %phi = phi i32 [ 0, %block3 ], [ %a, %block2 ]
84 call void @may_exit_1(i32 %phi) nounwind
90 ; It's OK to PRE an instruction that is guaranteed to be safe to execute
92 ; TODO: Does it make any sense in this case?
93 define i32 @test4(i32 %p, i32 %q) {
99 %cmp = icmp eq i32 %p, %q
100 br i1 %cmp, label %block2, label %block3
110 ; CHECK-NEXT: %b.pre-phi = phi i32
111 ; CHECK-NEXT: call void @may_exit(
112 ; CHECK-NEXT: ret i32 %b
115 call void @may_exit() nounwind
120 ; It is OK to PRE across implicit control flow if we don't insert new
122 define i32 @test5(i1 %cond, i32 %p, i32 %q) {
124 ; CHECK-LABEL: @test5
128 br i1 %cond, label %block2, label %block3
139 ; CHECK-NEXT: %c.pre-phi = phi i32 [ %b, %block3 ], [ %a, %block2 ]
140 ; CHECK-NEXT: call void @may_exit()
141 ; CHECK-NEXT: ret i32 %c.pre-phi
144 call void @may_exit() nounwind