1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=indvars -replexitval=always -S | FileCheck %s
3 ; Make sure IndVars preserves LCSSA form, especially across loop nests.
5 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
7 define void @PR18642(i32 %x) {
8 ; CHECK-LABEL: @PR18642(
10 ; CHECK-NEXT: br label [[OUTER_HEADER:%.*]]
11 ; CHECK: outer.header:
12 ; CHECK-NEXT: br label [[INNER_HEADER:%.*]]
13 ; CHECK: inner.header:
14 ; CHECK-NEXT: br i1 false, label [[INNER_LATCH:%.*]], label [[OUTER_LATCH:%.*]]
16 ; CHECK-NEXT: br i1 true, label [[INNER_HEADER]], label [[EXIT_LOOPEXIT:%.*]]
18 ; CHECK-NEXT: br i1 false, label [[OUTER_HEADER]], label [[EXIT_LOOPEXIT1:%.*]]
19 ; CHECK: exit.loopexit:
20 ; CHECK-NEXT: [[INC_LCSSA:%.*]] = phi i32 [ -2147483648, [[INNER_LATCH]] ]
21 ; CHECK-NEXT: br label [[EXIT:%.*]]
22 ; CHECK: exit.loopexit1:
23 ; CHECK-NEXT: br label [[EXIT]]
25 ; CHECK-NEXT: [[EXIT_PHI:%.*]] = phi i32 [ [[INC_LCSSA]], [[EXIT_LOOPEXIT]] ], [ undef, [[EXIT_LOOPEXIT1]] ]
26 ; CHECK-NEXT: ret void
29 br label %outer.header
32 %outer.iv = phi i32 [ 0, %entry ], [ %x, %outer.latch ]
33 br label %inner.header
36 %inner.iv = phi i32 [ undef, %outer.header ], [ %inc, %inner.latch ]
37 %cmp1 = icmp slt i32 %inner.iv, %outer.iv
38 br i1 %cmp1, label %inner.latch, label %outer.latch
41 %inc = add nsw i32 %inner.iv, 1
42 %cmp2 = icmp slt i32 %inner.iv, %outer.iv
43 br i1 %cmp2, label %inner.header, label %exit
46 br i1 false, label %outer.header, label %exit
49 %exit.phi = phi i32 [ %inc, %inner.latch ], [ undef, %outer.latch ]
53 define i64 @unconditional_exit_simplification(i64 %arg) {
54 ; CHECK-LABEL: @unconditional_exit_simplification(
56 ; CHECK-NEXT: br label [[LOOP1:%.*]]
58 ; CHECK-NEXT: br label [[LOOP2:%.*]]
60 ; CHECK-NEXT: [[IV2:%.*]] = phi i64 [ 0, [[LOOP1]] ], [ 1, [[LOOP2]] ]
61 ; CHECK-NEXT: br i1 true, label [[LOOP2]], label [[LOOP1_LATCH:%.*]]
63 ; CHECK-NEXT: [[RES_LCSSA:%.*]] = phi i64 [ [[IV2]], [[LOOP2]] ]
64 ; CHECK-NEXT: br i1 false, label [[LOOP1]], label [[EXIT:%.*]]
66 ; CHECK-NEXT: [[RES_LCSSA2:%.*]] = phi i64 [ [[RES_LCSSA]], [[LOOP1_LATCH]] ]
67 ; CHECK-NEXT: ret i64 [[RES_LCSSA2]]
73 %iv1 = phi i64 [ 0, %entry ], [ 1, %loop1.latch ]
77 %iv2 = phi i64 [ 0, %loop1 ], [ 1, %loop2 ]
78 %res = add nuw nsw i64 %iv1, %iv2
79 br i1 true, label %loop2, label %loop1.latch
82 %res.lcssa = phi i64 [ %res, %loop2 ]
83 br i1 false, label %loop1, label %exit
86 %res.lcssa2 = phi i64 [ %res.lcssa, %loop1.latch ]
90 ; Check that it does not crash because the incoming values of an LCSSA phi are
92 define void @pr57000(i64 %a) {
93 ; CHECK-LABEL: @pr57000(
95 ; CHECK-NEXT: br label [[LOOP_1_OUTER:%.*]]
96 ; CHECK: loop.1.loopexit:
97 ; CHECK-NEXT: br label [[LOOP_1_OUTER]]
98 ; CHECK: loop.1.outer:
99 ; CHECK-NEXT: br label [[LOOP_1:%.*]]
101 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle i64 [[A:%.*]], 2546175499358690212
102 ; CHECK-NEXT: [[CMP_EXT:%.*]] = zext i1 [[CMP]] to i8
103 ; CHECK-NEXT: br i1 [[CMP]], label [[LOOP_1]], label [[LOOP_2_HEADER_PREHEADER:%.*]]
104 ; CHECK: loop.2.header.preheader:
105 ; CHECK-NEXT: [[CMP_LCSSA2:%.*]] = phi i1 [ [[CMP]], [[LOOP_1]] ]
106 ; CHECK-NEXT: [[CMP_EXT_LCSSA:%.*]] = phi i8 [ [[CMP_EXT]], [[LOOP_1]] ]
107 ; CHECK-NEXT: br label [[LOOP_2_HEADER_OUTER:%.*]]
108 ; CHECK: loop.2.header.outer:
109 ; CHECK-NEXT: br label [[LOOP_2_HEADER:%.*]]
110 ; CHECK: loop.2.header:
111 ; CHECK-NEXT: switch i8 [[CMP_EXT_LCSSA]], label [[LOOP_1_LOOPEXIT:%.*]] [
112 ; CHECK-NEXT: i8 -1, label [[LOOP_2_LATCH:%.*]]
113 ; CHECK-NEXT: i8 1, label [[LOOP_2_LATCH]]
114 ; CHECK-NEXT: i8 4, label [[LOOP_2_HEADER]]
116 ; CHECK: loop.2.latch:
117 ; CHECK-NEXT: [[CMP_TRUNC_LCSSA1:%.*]] = phi i1 [ [[CMP_LCSSA2]], [[LOOP_2_HEADER]] ], [ [[CMP_LCSSA2]], [[LOOP_2_HEADER]] ]
118 ; CHECK-NEXT: call void @use(i1 [[CMP_TRUNC_LCSSA1]])
119 ; CHECK-NEXT: br label [[LOOP_2_HEADER_OUTER]]
125 %p.1 = phi i1 [ 0 , %entry ], [ %p.1, %loop.1 ], [ %p.2, %loop.2.header ]
126 %cmp = icmp sle i64 %a, 2546175499358690212
127 %cmp.ext = zext i1 %cmp to i8
128 br i1 %cmp, label %loop.1, label %loop.2.header
131 %p.2 = phi i1 [ %p.1, %loop.1 ], [ %p.2, %loop.2.header ], [ %cmp, %loop.2.latch ]
132 %cmp.trunc = trunc i8 %cmp.ext to i1
133 switch i8 %cmp.ext, label %loop.1 [
134 i8 -1, label %loop.2.latch
135 i8 1, label %loop.2.latch
136 i8 4, label %loop.2.header
140 call void @use(i1 %cmp.trunc)
141 br label %loop.2.header
144 define void @D149435(i16 %arg) {
145 ; CHECK-LABEL: @D149435(
146 ; CHECK-NEXT: br label [[LOOP1:%.*]]
148 ; CHECK-NEXT: [[FR:%.*]] = freeze i16 [[ARG:%.*]]
149 ; CHECK-NEXT: [[ARRAYIDX_IDX:%.*]] = shl i16 [[FR]], 1
150 ; CHECK-NEXT: [[OR:%.*]] = or disjoint i16 [[ARRAYIDX_IDX]], 1
151 ; CHECK-NEXT: br i1 false, label [[LOOP1]], label [[LOOP2_PREHEADER:%.*]]
152 ; CHECK: loop2.preheader:
153 ; CHECK-NEXT: [[FR_LCSSA:%.*]] = phi i16 [ [[FR]], [[LOOP1]] ]
154 ; CHECK-NEXT: [[OR_LCSSA:%.*]] = phi i16 [ [[OR]], [[LOOP1]] ]
155 ; CHECK-NEXT: [[UMAX:%.*]] = call i16 @llvm.umax.i16(i16 [[OR_LCSSA]], i16 2)
156 ; CHECK-NEXT: [[TMP1:%.*]] = add i16 [[UMAX]], -1
157 ; CHECK-NEXT: [[TMP2:%.*]] = shl i16 [[FR_LCSSA]], 1
158 ; CHECK-NEXT: [[TMP3:%.*]] = sub i16 [[TMP1]], [[TMP2]]
159 ; CHECK-NEXT: [[TMP4:%.*]] = icmp eq i16 [[TMP3]], 0
160 ; CHECK-NEXT: [[UMAX1:%.*]] = call i16 @llvm.umax.i16(i16 [[ARG]], i16 2)
161 ; CHECK-NEXT: [[TMP5:%.*]] = sub i16 [[UMAX1]], [[ARG]]
162 ; CHECK-NEXT: [[TMP6:%.*]] = icmp eq i16 [[TMP5]], 0
163 ; CHECK-NEXT: br label [[LOOP2:%.*]]
165 ; CHECK-NEXT: br i1 [[TMP4]], label [[TRAP:%.*]], label [[FOR_BODY8:%.*]]
167 ; CHECK-NEXT: br i1 [[TMP6]], label [[TRAP]], label [[LOOP2_LATCH:%.*]]
168 ; CHECK: loop2.latch:
169 ; CHECK-NEXT: br i1 false, label [[LOOP2]], label [[TRAP]]
171 ; CHECK-NEXT: unreachable
176 %fr = freeze i16 %arg
177 %arrayidx.idx = shl i16 %fr, 1
178 %or = or disjoint i16 %arrayidx.idx, 1
179 br i1 false, label %loop1, label %loop2.preheader
185 %iv = phi i16 [ %iv.next, %loop2.latch ], [ 0, %loop2.preheader ]
186 %add = add i16 %or, %iv
187 %cmp = icmp ugt i16 %add, 1
188 br i1 %cmp, label %trap, label %for.body8
191 %add2 = add i16 %arg, %iv
192 %cmp2 = icmp ugt i16 %add2, 1
193 br i1 %cmp2, label %trap, label %loop2.latch
196 %iv.next = add i16 %iv, 1
197 br i1 false, label %loop2, label %trap
203 declare void @use(i1)