1cee313d2SEric Christopher; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
25249e6f2SArthur Eubanks; RUN: opt -S -enable-loop-simplifycfg-term-folding=true -passes='require<domtree>,loop(loop-simplifycfg)' -verify-loop-info -verify-dom-info -verify-loop-lcssa < %s | FileCheck %s
3e11354c0SNikita Popov; RUN: opt -S -enable-loop-simplifycfg-term-folding=true -loop-simplifycfg -verify-memoryssa -verify-loop-info -verify-dom-info -verify-loop-lcssa < %s | FileCheck %s
4cee313d2SEric Christopher
5cee313d2SEric Christophertarget datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
6cee313d2SEric Christopher
7cee313d2SEric Christopherdefine void @c() {
8cee313d2SEric Christopher; CHECK-LABEL: @c(
9cee313d2SEric Christopher; CHECK-NEXT:  entry:
10cee313d2SEric Christopher; CHECK-NEXT:    br label [[D:%.*]]
11cee313d2SEric Christopher; CHECK:       d.loopexit:
12cee313d2SEric Christopher; CHECK-NEXT:    [[DOTLCSSA:%.*]] = phi i32 [ [[TMP1:%.*]], [[FOR_COND:%.*]] ]
13cee313d2SEric Christopher; CHECK-NEXT:    br label [[D]]
14cee313d2SEric Christopher; CHECK:       d:
15cee313d2SEric Christopher; CHECK-NEXT:    [[TMP0:%.*]] = phi i32 [ undef, [[ENTRY:%.*]] ], [ [[DOTLCSSA]], [[D_LOOPEXIT:%.*]] ]
16cee313d2SEric Christopher; CHECK-NEXT:    br label [[FOR_COND]]
17cee313d2SEric Christopher; CHECK:       for.cond:
18cee313d2SEric Christopher; CHECK-NEXT:    [[TMP1]] = phi i32 [ [[TMP0]], [[D]] ], [ 0, [[IF_END:%.*]] ]
19cee313d2SEric Christopher; CHECK-NEXT:    [[TOBOOL2:%.*]] = icmp eq i32 [[TMP1]], 0
20cee313d2SEric Christopher; CHECK-NEXT:    br i1 [[TOBOOL2]], label [[IF_END]], label [[D_LOOPEXIT]]
21cee313d2SEric Christopher; CHECK:       if.end:
22cee313d2SEric Christopher; CHECK-NEXT:    br label [[FOR_COND]]
23cee313d2SEric Christopher;
24cee313d2SEric Christopherentry:
25cee313d2SEric Christopher  br label %d
26cee313d2SEric Christopher
27cee313d2SEric Christopherd.loopexit:                                       ; preds = %if.end.7, %for.body
28cee313d2SEric Christopher  %.lcssa = phi i32 [ %1, %for.body ], [ 0, %if.end.7 ]
29cee313d2SEric Christopher  br label %d
30cee313d2SEric Christopher
31cee313d2SEric Christopherd:                                                ; preds = %d.loopexit, %entry
32cee313d2SEric Christopher  %0 = phi i32 [ undef, %entry ], [ %.lcssa, %d.loopexit ]
33cee313d2SEric Christopher  br label %for.cond
34cee313d2SEric Christopher
35cee313d2SEric Christopherfor.cond:                                         ; preds = %if.end.8, %d
36cee313d2SEric Christopher  %1 = phi i32 [ %0, %d ], [ 0, %if.end.8 ]
37cee313d2SEric Christopher  br label %for.body
38cee313d2SEric Christopher
39cee313d2SEric Christopherfor.body:                                         ; preds = %for.cond
40cee313d2SEric Christopher  %tobool2 = icmp eq i32 %1, 0
41cee313d2SEric Christopher  br i1 %tobool2, label %if.end, label %d.loopexit
42cee313d2SEric Christopher
43cee313d2SEric Christopherif.end:                                           ; preds = %for.body
44cee313d2SEric Christopher  br label %if.end.7
45cee313d2SEric Christopher
46cee313d2SEric Christopherif.end.7:                                         ; preds = %if.end
47cee313d2SEric Christopher  br i1 true, label %if.end.8, label %d.loopexit
48cee313d2SEric Christopher
49cee313d2SEric Christopherif.end.8:                                         ; preds = %if.end.7
50cee313d2SEric Christopher  br label %for.cond
51cee313d2SEric Christopher}
52cee313d2SEric Christopher
53cee313d2SEric Christopherdefine void @test_01() {
54cee313d2SEric Christopher; CHECK-LABEL: @test_01(
55cee313d2SEric Christopher; CHECK-NEXT:  entry:
56cee313d2SEric Christopher; CHECK-NEXT:    br label [[FOR_COND:%.*]]
57cee313d2SEric Christopher; CHECK:       for.cond.loopexit:
58cee313d2SEric Christopher; CHECK-NEXT:    br label [[FOR_COND]]
59cee313d2SEric Christopher; CHECK:       for.cond:
60*3fa2411dSNuno Lopes; CHECK-NEXT:    [[INC41_LCSSA3:%.*]] = phi i16 [ poison, [[FOR_COND_LOOPEXIT:%.*]] ], [ undef, [[ENTRY:%.*]] ]
61cee313d2SEric Christopher; CHECK-NEXT:    switch i32 0, label [[FOR_COND_SPLIT:%.*]] [
62cee313d2SEric Christopher; CHECK-NEXT:    i32 1, label [[FOR_COND_LOOPEXIT]]
63cee313d2SEric Christopher; CHECK-NEXT:    ]
64cee313d2SEric Christopher; CHECK:       for.cond.split:
65cee313d2SEric Christopher; CHECK-NEXT:    [[INC41_LCSSA3_LCSSA:%.*]] = phi i16 [ [[INC41_LCSSA3]], [[FOR_COND]] ]
66cee313d2SEric Christopher; CHECK-NEXT:    br label [[WHILE_COND:%.*]]
67cee313d2SEric Christopher; CHECK:       while.cond:
68cee313d2SEric Christopher; CHECK-NEXT:    [[INC41:%.*]] = phi i16 [ [[INC4:%.*]], [[WHILE_COND]] ], [ [[INC41_LCSSA3_LCSSA]], [[FOR_COND_SPLIT]] ]
69cee313d2SEric Christopher; CHECK-NEXT:    [[INC4]] = add nsw i16 [[INC41]], 1
70cee313d2SEric Christopher; CHECK-NEXT:    br label [[WHILE_COND]]
71cee313d2SEric Christopher;
72cee313d2SEric Christopherentry:
73cee313d2SEric Christopher  br label %for.cond
74cee313d2SEric Christopher
75cee313d2SEric Christopherfor.cond.loopexit:                                ; preds = %while.cond
76cee313d2SEric Christopher  %inc41.lcssa = phi i16 [ %inc41, %while.cond ]
77cee313d2SEric Christopher  br label %for.cond
78cee313d2SEric Christopher
79cee313d2SEric Christopherfor.cond:                                         ; preds = %for.cond.loopexit, %entry
80cee313d2SEric Christopher  %inc41.lcssa3 = phi i16 [ %inc41.lcssa, %for.cond.loopexit ], [ undef, %entry ]
81cee313d2SEric Christopher  br label %while.cond
82cee313d2SEric Christopher
83cee313d2SEric Christopherwhile.cond:                                       ; preds = %while.body, %for.cond
84cee313d2SEric Christopher  %inc41 = phi i16 [ %inc4, %while.body ], [ %inc41.lcssa3, %for.cond ]
85cee313d2SEric Christopher  br i1 true, label %while.body, label %for.cond.loopexit
86cee313d2SEric Christopher
87cee313d2SEric Christopherwhile.body:                                       ; preds = %while.cond
88cee313d2SEric Christopher  %inc4 = add nsw i16 %inc41, 1
89cee313d2SEric Christopher  br label %while.cond
90cee313d2SEric Christopher}
91cee313d2SEric Christopher
92cee313d2SEric Christopherdefine void @bar() {
93cee313d2SEric Christopher; CHECK-LABEL: @bar(
94cee313d2SEric Christopher; CHECK-NEXT:  bb:
95cee313d2SEric Christopher; CHECK-NEXT:    switch i32 0, label [[BB_SPLIT:%.*]] [
96cee313d2SEric Christopher; CHECK-NEXT:    i32 1, label [[BB10:%.*]]
97cee313d2SEric Christopher; CHECK-NEXT:    ]
98cee313d2SEric Christopher; CHECK:       bb.split:
99cee313d2SEric Christopher; CHECK-NEXT:    br label [[BB1:%.*]]
100cee313d2SEric Christopher; CHECK:       bb1:
101cee313d2SEric Christopher; CHECK-NEXT:    [[TMP:%.*]] = phi i32 [ [[TMP7:%.*]], [[BB6:%.*]] ], [ undef, [[BB_SPLIT]] ]
102cee313d2SEric Christopher; CHECK-NEXT:    switch i32 undef, label [[BB5:%.*]] [
103cee313d2SEric Christopher; CHECK-NEXT:    i32 0, label [[BB6]]
104cee313d2SEric Christopher; CHECK-NEXT:    i32 1, label [[BB8:%.*]]
105cee313d2SEric Christopher; CHECK-NEXT:    ]
106cee313d2SEric Christopher; CHECK:       bb5:
107cee313d2SEric Christopher; CHECK-NEXT:    ret void
108cee313d2SEric Christopher; CHECK:       bb6:
109cee313d2SEric Christopher; CHECK-NEXT:    [[TMP7]] = add i32 undef, 123
110cee313d2SEric Christopher; CHECK-NEXT:    br label [[BB1]]
111cee313d2SEric Christopher; CHECK:       bb8:
112cee313d2SEric Christopher; CHECK-NEXT:    [[TMP9:%.*]] = phi i32 [ [[TMP]], [[BB1]] ]
113cee313d2SEric Christopher; CHECK-NEXT:    [[USE:%.*]] = add i32 [[TMP9]], 1
114cee313d2SEric Christopher; CHECK-NEXT:    ret void
115cee313d2SEric Christopher; CHECK:       bb10:
116cee313d2SEric Christopher; CHECK-NEXT:    ret void
117cee313d2SEric Christopher;
118cee313d2SEric Christopher
119cee313d2SEric Christopherbb:
120cee313d2SEric Christopher  br label %bb1
121cee313d2SEric Christopher
122cee313d2SEric Christopherbb1:                                              ; preds = %bb6, %bb
123cee313d2SEric Christopher  %tmp = phi i32 [ %tmp7, %bb6 ], [ undef, %bb ]
124cee313d2SEric Christopher  br i1 false, label %bb2, label %bb4
125cee313d2SEric Christopher
126cee313d2SEric Christopherbb2:                                              ; preds = %bb1
127cee313d2SEric Christopher  switch i32 undef, label %bb10 [
128cee313d2SEric Christopher  i32 0, label %bb3
129cee313d2SEric Christopher  i32 1, label %bb8
130cee313d2SEric Christopher  ]
131cee313d2SEric Christopher
132cee313d2SEric Christopherbb3:                                              ; preds = %bb2
133cee313d2SEric Christopher  br label %bb6
134cee313d2SEric Christopher
135cee313d2SEric Christopherbb4:                                              ; preds = %bb1
136cee313d2SEric Christopher  switch i32 undef, label %bb5 [
137cee313d2SEric Christopher  i32 0, label %bb6
138cee313d2SEric Christopher  i32 1, label %bb8
139cee313d2SEric Christopher  ]
140cee313d2SEric Christopher
141cee313d2SEric Christopherbb5:                                              ; preds = %bb4
142cee313d2SEric Christopher  ret void
143cee313d2SEric Christopher
144cee313d2SEric Christopherbb6:                                              ; preds = %bb4, %bb3
145cee313d2SEric Christopher  %tmp7 = add i32 undef, 123
146cee313d2SEric Christopher  br label %bb1
147cee313d2SEric Christopher
148cee313d2SEric Christopherbb8:                                              ; preds = %bb4, %bb2
149cee313d2SEric Christopher  %tmp9 = phi i32 [ %tmp, %bb2 ], [ %tmp, %bb4 ]
150cee313d2SEric Christopher  %use = add i32 %tmp9, 1
151cee313d2SEric Christopher  ret void
152cee313d2SEric Christopher
153cee313d2SEric Christopherbb10:                                             ; preds = %bb2
154cee313d2SEric Christopher  ret void
155cee313d2SEric Christopher}
156cee313d2SEric Christopher
157cee313d2SEric Christopherdefine void @memlcssa() {
158cee313d2SEric Christopher; CHECK-LABEL: @memlcssa(
159cee313d2SEric Christopher; CHECK-NEXT:  entry:
160cee313d2SEric Christopher; CHECK-NEXT:    switch i32 0, label [[ENTRY_SPLIT:%.*]] [
161cee313d2SEric Christopher; CHECK-NEXT:    i32 1, label [[DEFAULT_BB:%.*]]
162cee313d2SEric Christopher; CHECK-NEXT:    ]
163cee313d2SEric Christopher; CHECK:       entry.split:
164cee313d2SEric Christopher; CHECK-NEXT:    br label [[FOR_BODY:%.*]]
165cee313d2SEric Christopher; CHECK:       for.body:
166cee313d2SEric Christopher; CHECK-NEXT:    call void @foo()
167cee313d2SEric Christopher; CHECK-NEXT:    br label [[FOR_BODY]]
168cee313d2SEric Christopher; CHECK:       default.bb:
169cee313d2SEric Christopher; CHECK-NEXT:    unreachable
170cee313d2SEric Christopher;
171cee313d2SEric Christopherentry:
172cee313d2SEric Christopher  br label %for.body
173cee313d2SEric Christopher
174cee313d2SEric Christopherfor.body:                                         ; preds = %exit, %entry
175cee313d2SEric Christopher  br label %switch.bb
176cee313d2SEric Christopher
177cee313d2SEric Christopherswitch.bb:                                        ; preds = %for.body
178cee313d2SEric Christopher  switch i2 1, label %default.bb [
179cee313d2SEric Christopher  i2 1, label %case.bb
180cee313d2SEric Christopher  ]
181cee313d2SEric Christopher
182cee313d2SEric Christophercase.bb:                                          ; preds = %switch
183cee313d2SEric Christopher  br label %exit
184cee313d2SEric Christopher
185cee313d2SEric Christopherdefault.bb:                                       ; preds = %switch
186cee313d2SEric Christopher  unreachable
187cee313d2SEric Christopher
188cee313d2SEric Christopherexit:                                             ; preds = %case.bb
189cee313d2SEric Christopher  call void @foo()
190cee313d2SEric Christopher  br label %for.body
191cee313d2SEric Christopher}
192cee313d2SEric Christopher
193cee313d2SEric Christopherdeclare void @foo()
194