1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -enable-loop-simplifycfg-term-folding=true -loop-simplifycfg -verify-loop-info -verify-dom-info -verify-loop-lcssa < %s | FileCheck %s
3 ; RUN: opt -S -enable-loop-simplifycfg-term-folding=true -passes='require<domtree>,loop(simplify-cfg)' -verify-loop-info -verify-dom-info -verify-loop-lcssa < %s | FileCheck %s
4 ; RUN: opt -S -enable-loop-simplifycfg-term-folding=true -loop-simplifycfg -enable-mssa-loop-dependency=true -verify-memoryssa -verify-loop-info -verify-dom-info -verify-loop-lcssa < %s | FileCheck %s
6 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
11 ; CHECK-NEXT: br label [[D:%.*]]
13 ; CHECK-NEXT: [[DOTLCSSA:%.*]] = phi i32 [ [[TMP1:%.*]], [[FOR_COND:%.*]] ]
14 ; CHECK-NEXT: br label [[D]]
16 ; CHECK-NEXT: [[TMP0:%.*]] = phi i32 [ undef, [[ENTRY:%.*]] ], [ [[DOTLCSSA]], [[D_LOOPEXIT:%.*]] ]
17 ; CHECK-NEXT: br label [[FOR_COND]]
19 ; CHECK-NEXT: [[TMP1]] = phi i32 [ [[TMP0]], [[D]] ], [ 0, [[IF_END:%.*]] ]
20 ; CHECK-NEXT: [[TOBOOL2:%.*]] = icmp eq i32 [[TMP1]], 0
21 ; CHECK-NEXT: br i1 [[TOBOOL2]], label [[IF_END]], label [[D_LOOPEXIT]]
23 ; CHECK-NEXT: br label [[FOR_COND]]
28 d.loopexit: ; preds = %if.end.7, %for.body
29 %.lcssa = phi i32 [ %1, %for.body ], [ 0, %if.end.7 ]
32 d: ; preds = %d.loopexit, %entry
33 %0 = phi i32 [ undef, %entry ], [ %.lcssa, %d.loopexit ]
36 for.cond: ; preds = %if.end.8, %d
37 %1 = phi i32 [ %0, %d ], [ 0, %if.end.8 ]
40 for.body: ; preds = %for.cond
41 %tobool2 = icmp eq i32 %1, 0
42 br i1 %tobool2, label %if.end, label %d.loopexit
44 if.end: ; preds = %for.body
47 if.end.7: ; preds = %if.end
48 br i1 true, label %if.end.8, label %d.loopexit
50 if.end.8: ; preds = %if.end.7
54 define void @test_01() {
55 ; CHECK-LABEL: @test_01(
57 ; CHECK-NEXT: br label [[FOR_COND:%.*]]
58 ; CHECK: for.cond.loopexit:
59 ; CHECK-NEXT: br label [[FOR_COND]]
61 ; CHECK-NEXT: [[INC41_LCSSA3:%.*]] = phi i16 [ undef, [[FOR_COND_LOOPEXIT:%.*]] ], [ undef, [[ENTRY:%.*]] ]
62 ; CHECK-NEXT: switch i32 0, label [[FOR_COND_SPLIT:%.*]] [
63 ; CHECK-NEXT: i32 1, label [[FOR_COND_LOOPEXIT]]
65 ; CHECK: for.cond.split:
66 ; CHECK-NEXT: [[INC41_LCSSA3_LCSSA:%.*]] = phi i16 [ [[INC41_LCSSA3]], [[FOR_COND]] ]
67 ; CHECK-NEXT: br label [[WHILE_COND:%.*]]
69 ; CHECK-NEXT: [[INC41:%.*]] = phi i16 [ [[INC4:%.*]], [[WHILE_COND]] ], [ [[INC41_LCSSA3_LCSSA]], [[FOR_COND_SPLIT]] ]
70 ; CHECK-NEXT: [[INC4]] = add nsw i16 [[INC41]], 1
71 ; CHECK-NEXT: br label [[WHILE_COND]]
76 for.cond.loopexit: ; preds = %while.cond
77 %inc41.lcssa = phi i16 [ %inc41, %while.cond ]
80 for.cond: ; preds = %for.cond.loopexit, %entry
81 %inc41.lcssa3 = phi i16 [ %inc41.lcssa, %for.cond.loopexit ], [ undef, %entry ]
84 while.cond: ; preds = %while.body, %for.cond
85 %inc41 = phi i16 [ %inc4, %while.body ], [ %inc41.lcssa3, %for.cond ]
86 br i1 true, label %while.body, label %for.cond.loopexit
88 while.body: ; preds = %while.cond
89 %inc4 = add nsw i16 %inc41, 1
96 ; CHECK-NEXT: switch i32 0, label [[BB_SPLIT:%.*]] [
97 ; CHECK-NEXT: i32 1, label [[BB10:%.*]]
100 ; CHECK-NEXT: br label [[BB1:%.*]]
102 ; CHECK-NEXT: [[TMP:%.*]] = phi i32 [ [[TMP7:%.*]], [[BB6:%.*]] ], [ undef, [[BB_SPLIT]] ]
103 ; CHECK-NEXT: switch i32 undef, label [[BB5:%.*]] [
104 ; CHECK-NEXT: i32 0, label [[BB6]]
105 ; CHECK-NEXT: i32 1, label [[BB8:%.*]]
108 ; CHECK-NEXT: ret void
110 ; CHECK-NEXT: [[TMP7]] = add i32 undef, 123
111 ; CHECK-NEXT: br label [[BB1]]
113 ; CHECK-NEXT: [[TMP9:%.*]] = phi i32 [ [[TMP]], [[BB1]] ]
114 ; CHECK-NEXT: [[USE:%.*]] = add i32 [[TMP9]], 1
115 ; CHECK-NEXT: ret void
117 ; CHECK-NEXT: ret void
123 bb1: ; preds = %bb6, %bb
124 %tmp = phi i32 [ %tmp7, %bb6 ], [ undef, %bb ]
125 br i1 false, label %bb2, label %bb4
128 switch i32 undef, label %bb10 [
137 switch i32 undef, label %bb5 [
145 bb6: ; preds = %bb4, %bb3
146 %tmp7 = add i32 undef, 123
149 bb8: ; preds = %bb4, %bb2
150 %tmp9 = phi i32 [ %tmp, %bb2 ], [ %tmp, %bb4 ]
151 %use = add i32 %tmp9, 1
158 define void @memlcssa() {
159 ; CHECK-LABEL: @memlcssa(
161 ; CHECK-NEXT: switch i32 0, label [[ENTRY_SPLIT:%.*]] [
162 ; CHECK-NEXT: i32 1, label [[DEFAULT_BB:%.*]]
164 ; CHECK: entry.split:
165 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
167 ; CHECK-NEXT: call void @foo()
168 ; CHECK-NEXT: br label [[FOR_BODY]]
170 ; CHECK-NEXT: unreachable
175 for.body: ; preds = %exit, %entry
178 switch.bb: ; preds = %for.body
179 switch i2 1, label %default.bb [
183 case.bb: ; preds = %switch
186 default.bb: ; preds = %switch
189 exit: ; preds = %case.bb