1 ; RUN: opt < %s -passes=gvn -enable-pre -S | FileCheck %s
2 ; RUN: opt < %s -passes="gvn<pre>" -enable-pre=false -S | FileCheck %s
4 declare void @may_exit() nounwind
6 declare void @may_exit_1(i32) nounwind
8 define i32 @main(i32 %p, i32 %q) {
13 %cmp = icmp eq i32 %p, %q
14 br i1 %cmp, label %block2, label %block3
22 ; CHECK: %.pre = add i32 %p, 1
23 ; CHECK-NEXT: br label %block4
28 ; CHECK: %b.pre-phi = phi i32 [ %.pre, %block3 ], [ %a, %block2 ]
29 ; CHECK-NEXT: ret i32 %b.pre-phi
32 ; Don't PRE across implicit control flow.
33 define i32 @test2(i32 %p, i32 %q) {
39 %cmp = icmp eq i32 %p, %q
40 br i1 %cmp, label %block2, label %block3
50 ; CHECK-NEXT: call void @may_exit(
51 ; CHECK-NEXT: %b = sdiv
52 ; CHECK-NEXT: ret i32 %b
55 call void @may_exit() nounwind
60 ; Don't PRE across implicit control flow.
61 define i32 @test3(i32 %p, i32 %q, i1 %r) {
67 br i1 %r, label %block2, label %block3
80 ; CHECK-NEXT: call void @may_exit_1(
81 ; CHECK-NEXT: %b = sdiv
82 ; CHECK-NEXT: ret i32 %b
84 %phi = phi i32 [ 0, %block3 ], [ %a, %block2 ]
85 call void @may_exit_1(i32 %phi) nounwind
91 ; It's OK to PRE an instruction that is guaranteed to be safe to execute
93 ; TODO: Does it make any sense in this case?
94 define i32 @test4(i32 %p, i32 %q) {
100 %cmp = icmp eq i32 %p, %q
101 br i1 %cmp, label %block2, label %block3
111 ; CHECK-NEXT: %b.pre-phi = phi i32
112 ; CHECK-NEXT: call void @may_exit(
113 ; CHECK-NEXT: ret i32 %b
116 call void @may_exit() nounwind
121 ; It is OK to PRE across implicit control flow if we don't insert new
123 define i32 @test5(i1 %cond, i32 %p, i32 %q) {
125 ; CHECK-LABEL: @test5
129 br i1 %cond, label %block2, label %block3
140 ; CHECK-NEXT: %c.pre-phi = phi i32 [ %b, %block3 ], [ %a, %block2 ]
141 ; CHECK-NEXT: call void @may_exit()
142 ; CHECK-NEXT: ret i32 %c.pre-phi
145 call void @may_exit() nounwind