1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; 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
3 ; RUN: opt -S -enable-loop-simplifycfg-term-folding=true -passes=loop-simplifycfg -verify-memoryssa -verify-loop-info -verify-dom-info -verify-loop-lcssa < %s | FileCheck %s
5 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
10 ; CHECK-NEXT: br label [[D:%.*]]
12 ; CHECK-NEXT: [[DOTLCSSA:%.*]] = phi i32 [ [[TMP1:%.*]], [[FOR_COND:%.*]] ]
13 ; CHECK-NEXT: br label [[D]]
15 ; CHECK-NEXT: [[TMP0:%.*]] = phi i32 [ undef, [[ENTRY:%.*]] ], [ [[DOTLCSSA]], [[D_LOOPEXIT:%.*]] ]
16 ; CHECK-NEXT: br label [[FOR_COND]]
18 ; CHECK-NEXT: [[TMP1]] = phi i32 [ [[TMP0]], [[D]] ], [ 0, [[IF_END:%.*]] ]
19 ; CHECK-NEXT: [[TOBOOL2:%.*]] = icmp eq i32 [[TMP1]], 0
20 ; CHECK-NEXT: br i1 [[TOBOOL2]], label [[IF_END]], label [[D_LOOPEXIT]]
22 ; CHECK-NEXT: br label [[FOR_COND]]
27 d.loopexit: ; preds = %if.end.7, %for.body
28 %.lcssa = phi i32 [ %1, %for.body ], [ 0, %if.end.7 ]
31 d: ; preds = %d.loopexit, %entry
32 %0 = phi i32 [ undef, %entry ], [ %.lcssa, %d.loopexit ]
35 for.cond: ; preds = %if.end.8, %d
36 %1 = phi i32 [ %0, %d ], [ 0, %if.end.8 ]
39 for.body: ; preds = %for.cond
40 %tobool2 = icmp eq i32 %1, 0
41 br i1 %tobool2, label %if.end, label %d.loopexit
43 if.end: ; preds = %for.body
46 if.end.7: ; preds = %if.end
47 br i1 true, label %if.end.8, label %d.loopexit
49 if.end.8: ; preds = %if.end.7
53 define void @test_01() {
54 ; CHECK-LABEL: @test_01(
56 ; CHECK-NEXT: br label [[FOR_COND:%.*]]
57 ; CHECK: for.cond.loopexit:
58 ; CHECK-NEXT: br label [[FOR_COND]]
60 ; CHECK-NEXT: [[INC41_LCSSA3:%.*]] = phi i16 [ poison, [[FOR_COND_LOOPEXIT:%.*]] ], [ undef, [[ENTRY:%.*]] ]
61 ; CHECK-NEXT: switch i32 0, label [[FOR_COND_SPLIT:%.*]] [
62 ; CHECK-NEXT: i32 1, label [[FOR_COND_LOOPEXIT]]
64 ; CHECK: for.cond.split:
65 ; CHECK-NEXT: [[INC41_LCSSA3_LCSSA:%.*]] = phi i16 [ [[INC41_LCSSA3]], [[FOR_COND]] ]
66 ; CHECK-NEXT: br label [[WHILE_COND:%.*]]
68 ; CHECK-NEXT: [[INC41:%.*]] = phi i16 [ [[INC4:%.*]], [[WHILE_COND]] ], [ [[INC41_LCSSA3_LCSSA]], [[FOR_COND_SPLIT]] ]
69 ; CHECK-NEXT: [[INC4]] = add nsw i16 [[INC41]], 1
70 ; CHECK-NEXT: br label [[WHILE_COND]]
75 for.cond.loopexit: ; preds = %while.cond
76 %inc41.lcssa = phi i16 [ %inc41, %while.cond ]
79 for.cond: ; preds = %for.cond.loopexit, %entry
80 %inc41.lcssa3 = phi i16 [ %inc41.lcssa, %for.cond.loopexit ], [ undef, %entry ]
83 while.cond: ; preds = %while.body, %for.cond
84 %inc41 = phi i16 [ %inc4, %while.body ], [ %inc41.lcssa3, %for.cond ]
85 br i1 true, label %while.body, label %for.cond.loopexit
87 while.body: ; preds = %while.cond
88 %inc4 = add nsw i16 %inc41, 1
95 ; CHECK-NEXT: switch i32 0, label [[BB_SPLIT:%.*]] [
96 ; CHECK-NEXT: i32 1, label [[BB10:%.*]]
99 ; CHECK-NEXT: br label [[BB1:%.*]]
101 ; CHECK-NEXT: [[TMP:%.*]] = phi i32 [ [[TMP7:%.*]], [[BB6:%.*]] ], [ undef, [[BB_SPLIT]] ]
102 ; CHECK-NEXT: switch i32 undef, label [[BB5:%.*]] [
103 ; CHECK-NEXT: i32 0, label [[BB6]]
104 ; CHECK-NEXT: i32 1, label [[BB8:%.*]]
107 ; CHECK-NEXT: ret void
109 ; CHECK-NEXT: [[TMP7]] = add i32 undef, 123
110 ; CHECK-NEXT: br label [[BB1]]
112 ; CHECK-NEXT: [[TMP9:%.*]] = phi i32 [ [[TMP]], [[BB1]] ]
113 ; CHECK-NEXT: [[USE:%.*]] = add i32 [[TMP9]], 1
114 ; CHECK-NEXT: ret void
116 ; CHECK-NEXT: ret void
122 bb1: ; preds = %bb6, %bb
123 %tmp = phi i32 [ %tmp7, %bb6 ], [ undef, %bb ]
124 br i1 false, label %bb2, label %bb4
127 switch i32 undef, label %bb10 [
136 switch i32 undef, label %bb5 [
144 bb6: ; preds = %bb4, %bb3
145 %tmp7 = add i32 undef, 123
148 bb8: ; preds = %bb4, %bb2
149 %tmp9 = phi i32 [ %tmp, %bb2 ], [ %tmp, %bb4 ]
150 %use = add i32 %tmp9, 1
157 define void @memlcssa() {
158 ; CHECK-LABEL: @memlcssa(
160 ; CHECK-NEXT: switch i32 0, label [[ENTRY_SPLIT:%.*]] [
161 ; CHECK-NEXT: i32 1, label [[DEFAULT_BB:%.*]]
163 ; CHECK: entry.split:
164 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
166 ; CHECK-NEXT: call void @foo()
167 ; CHECK-NEXT: br label [[FOR_BODY]]
169 ; CHECK-NEXT: unreachable
174 for.body: ; preds = %exit, %entry
177 switch.bb: ; preds = %for.body
178 switch i2 1, label %default.bb [
182 case.bb: ; preds = %switch
185 default.bb: ; preds = %switch
188 exit: ; preds = %case.bb