1 ; RUN: opt -passes='loop(unswitch),verify<loops>' -S < %s | FileCheck %s
2 ; RUN: opt -verify-memoryssa -passes='loop-mssa(unswitch),verify<loops>' -S < %s | FileCheck %s
4 define i32 @test(i32* %A, i1 %C) {
7 no_exit: ; preds = %no_exit.backedge, %entry
8 %i.0.0 = phi i32 [ 0, %entry ], [ %i.0.0.be, %no_exit.backedge ] ; <i32> [#uses=3]
9 %gep.upgrd.1 = zext i32 %i.0.0 to i64 ; <i64> [#uses=1]
10 %tmp.7 = getelementptr i32, i32* %A, i64 %gep.upgrd.1 ; <i32*> [#uses=4]
11 %tmp.13 = load i32, i32* %tmp.7 ; <i32> [#uses=2]
12 %tmp.14 = add i32 %tmp.13, 1 ; <i32> [#uses=1]
13 store i32 %tmp.14, i32* %tmp.7
14 br i1 %C, label %then, label %endif
15 then: ; preds = %no_exit
16 %tmp.29 = load i32, i32* %tmp.7 ; <i32> [#uses=1]
17 %tmp.30 = add i32 %tmp.29, 2 ; <i32> [#uses=1]
18 store i32 %tmp.30, i32* %tmp.7
19 %inc9 = add i32 %i.0.0, 1 ; <i32> [#uses=2]
20 %tmp.112 = icmp ult i32 %inc9, 100000 ; <i1> [#uses=1]
21 br i1 %tmp.112, label %no_exit.backedge, label %return
22 no_exit.backedge: ; preds = %endif, %then
23 %i.0.0.be = phi i32 [ %inc9, %then ], [ %inc, %endif ] ; <i32> [#uses=1]
25 endif: ; preds = %no_exit
26 %inc = add i32 %i.0.0, 1 ; <i32> [#uses=2]
27 %tmp.1 = icmp ult i32 %inc, 100000 ; <i1> [#uses=1]
28 br i1 %tmp.1, label %no_exit.backedge, label %return
29 return: ; preds = %endif, %then
33 ; This simple test would normally unswitch, but should be inhibited by the presence of
34 ; the noduplicate call.
36 ; CHECK-LABEL: @test2(
37 define i32 @test2(i32* %var) {
39 store i32 2, i32* %mem
40 %c = load i32, i32* %mem
46 %var_val = load i32, i32* %var
48 switch i32 %c, label %default [
54 call void @incf() noreturn nounwind
57 ; CHECK: call void @decf()
58 ; CHECK-NOT: call void @decf()
59 call void @decf() noreturn nounwind noduplicate
68 ; This simple test would normally unswitch, but should be inhibited by the presence of
69 ; the convergent call that is not control-dependent on the unswitch condition.
71 ; CHECK-LABEL: @test3(
72 define i32 @test3(i32* %var) {
74 store i32 2, i32* %mem
75 %c = load i32, i32* %mem
81 %var_val = load i32, i32* %var
83 ; CHECK: call void @conv()
84 ; CHECK-NOT: call void @conv()
85 call void @conv() convergent
87 switch i32 %c, label %default [
93 call void @incf() noreturn nounwind
96 call void @decf() noreturn nounwind
105 ; Make sure we don't unswitch, as we can not find an input value %a
106 ; that will effectively unswitch 0 or 3 out of the loop.
108 ; CHECK: define void @and_or_i2_as_switch_input(i2
110 ; This is an indication that the loop has NOT been unswitched.
113 define void @and_or_i2_as_switch_input(i2 %a) {
118 %i = phi i2 [ 0, %entry ], [ %inc, %for.inc ]
121 switch i2 %or, label %sw.default [
139 %inc = add nsw i2 %i, 1
140 %cmp = icmp slt i2 %inc, 3
141 br i1 %cmp, label %for.body, label %for.end
147 ; Make sure we don't unswitch, as we can not find an input value %a
148 ; that will effectively unswitch true/false out of the loop.
150 ; CHECK: define void @and_or_i1_as_branch_input(i1
152 ; This is an indication that the loop has NOT been unswitched.
155 define void @and_or_i1_as_branch_input(i1 %a) {
160 %i = phi i1 [ 0, %entry ], [ %inc, %for.inc ]
163 br i1 %or, label %sw.bb, label %sw.bb1
175 %inc = add nsw i1 %i, 1
176 %cmp = icmp slt i1 %inc, 1
177 br i1 %cmp, label %for.body, label %for.end
183 declare void @incf() noreturn
184 declare void @decf() noreturn
185 declare void @conv() convergent