1 ; RUN: opt -S -passes='print<scalar-evolution>,loop-deletion,print<scalar-evolution>' -verify-scev < %s 2>&1 | FileCheck %s --check-prefix=SCEV-EXPRS
2 ; RUN: opt -S -passes=loop-deletion < %s | FileCheck %s --check-prefix=IR-AFTER-TRANSFORM
4 ; Checking for a crash. Loop-deletion would change the loop
5 ; disposition of an instruction, but not update SCEV.
7 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
8 target triple = "x86_64-apple-macosx10.11.0"
10 define void @pr27570(i1 %c1) {
11 ; IR-AFTER-TRANSFORM-LABEL: @pr27570(
15 for.cond: ; preds = %for.cond14, %entry
16 %f.0 = phi i32 [ 20, %entry ], [ 0, %for.cond14 ]
19 for.body: ; preds = %for.inc11, %for.cond
20 ; IR-AFTER-TRANSFORM: for.body:
21 ; IR-AFTER-TRANSFORM: %cmp = icmp eq i32 %val, -1
22 ; IR-AFTER-TRANSFORM: %conv7 = zext i1 %cmp to i32
23 ; IR-AFTER-TRANSFORM: for.body6:
25 ; SCEV-EXPRS: %conv7 = zext i1 %cmp to i32
26 ; SCEV-EXPRS: %conv7 = zext i1 %cmp to i32
27 ; SCEV-EXPRS-NEXT: --> {{.*}} LoopDispositions: { %for.body: Variant, %for.cond: Variant, %for.body6: Invariant }
28 %val = phi i32 [ -20, %for.cond ], [ %inc12, %for.inc11 ]
29 %g.040 = phi i32 [ -20, %for.cond ], [ %and.lcssa, %for.inc11 ]
32 for.body6: ; preds = %for.body6, %for.body
33 %h.039 = phi i32 [ 1, %for.body ], [ %inc, %for.body6 ]
34 %g.138 = phi i32 [ %g.040, %for.body ], [ %and, %for.body6 ]
35 %cmp = icmp eq i32 %val, -1
36 %conv7 = zext i1 %cmp to i32
37 %add.i = add nsw i32 %conv7, %h.039
38 %sext = shl i32 %add.i, 24
39 %conv8 = ashr exact i32 %sext, 24
40 %cmp9 = icmp eq i32 %conv8, %f.0
41 %conv10 = zext i1 %cmp9 to i32
42 %and = and i32 %conv10, %g.138
43 %inc = add i32 %h.039, 1
44 %exit = icmp eq i32 %inc, 20000
45 br i1 %exit, label %for.inc11, label %for.body6
47 for.inc11: ; preds = %for.body6
48 %and.lcssa = phi i32 [ %and, %for.body6 ]
49 call void @sideeffect(i32 %and.lcssa)
50 %inc12 = add nsw i32 %val, 1
51 %tobool = icmp eq i32 %inc12, 0
52 br i1 %tobool, label %for.cond14, label %for.body
54 for.cond14: ; preds = %for.cond14, %for.inc11
55 br i1 %c1, label %for.cond, label %for.cond14
58 declare void @sideeffect(i32)
60 ; LoopDeletion removes the loop %for.body7.1. Make sure %inc.lcssa.1 in the loop
61 ; exit block is correctly invalidated.
63 define void @test2(ptr %bx, i64 %by) local_unnamed_addr align 2 {
64 ; IR-AFTER-TRANSFORM-LABEL: @test2(
65 ; IR-AFTER-TRANSFORM-NOT: for.body7.1:
67 ; SCEV-EXPRS-LABEL: test2
68 ; SCEV-EXPRS: %inc.lcssa.1 = phi i64 [ poison, %for.body7.preheader.1 ]
69 ; SCEV-EXPRS-NEXT: --> undef
71 %cmp = icmp sgt i64 %by, 0
72 br label %for.cond.preheader
74 for.cond.preheader: ; preds = %entry
75 br i1 %cmp, label %for.cond5.preheader.lr.ph, label %for.end14
77 for.cond5.preheader.lr.ph: ; preds = %for.cond.preheader
78 br label %for.cond5.preheader
80 for.cond.loopexit.loopexit: ; preds = %for.body10
81 %inc11.lcssa = phi i64 [ %inc11, %for.body10 ]
82 br label %for.cond.loopexit
84 for.cond.loopexit: ; preds = %for.cond8.preheader, %for.cond.loopexit.loopexit
85 %ca.3.lcssa = phi i64 [ %ca.2.lcssa, %for.cond8.preheader ], [ %inc11.lcssa, %for.cond.loopexit.loopexit ]
86 br i1 %cmp, label %for.cond5.preheader, label %for.end14.loopexit
88 for.cond5.preheader: ; preds = %for.cond.loopexit, %for.cond5.preheader.lr.ph
89 %ca.19 = phi i64 [ 0, %for.cond5.preheader.lr.ph ], [ %ca.3.lcssa, %for.cond.loopexit ]
90 br i1 false, label %for.cond8.preheader, label %for.body7.preheader
92 for.body7.preheader: ; preds = %for.cond5.preheader
95 for.cond8.preheader.loopexit: ; preds = %for.body7
96 %inc.lcssa = phi i64 [ %inc, %for.body7 ]
97 br label %for.cond8.preheader
99 for.cond8.preheader: ; preds = %for.cond8.preheader.loopexit, %for.cond5.preheader
100 %ca.2.lcssa = phi i64 [ %ca.19, %for.cond5.preheader ], [ %inc.lcssa, %for.cond8.preheader.loopexit ]
101 br i1 true, label %for.body10.preheader, label %for.cond.loopexit
103 for.body10.preheader: ; preds = %for.cond8.preheader
106 for.body7: ; preds = %for.body7, %for.body7.preheader
107 %ca.26 = phi i64 [ %inc, %for.body7 ], [ %ca.19, %for.body7.preheader ]
108 %inc = add nsw i64 %ca.26, 1
109 %arrayidx = getelementptr inbounds double, ptr %bx, i64 %ca.26
110 store double 0.000000e+00, ptr %arrayidx, align 8
111 br i1 false, label %for.cond8.preheader.loopexit, label %for.body7
113 for.body10: ; preds = %for.body10, %for.body10.preheader
114 %ca.37 = phi i64 [ %inc11, %for.body10 ], [ %ca.2.lcssa, %for.body10.preheader ]
115 %inc11 = add nsw i64 %ca.37, 1
116 br i1 true, label %for.body10, label %for.cond.loopexit.loopexit
118 for.end14.loopexit: ; preds = %for.cond.loopexit
121 for.end14: ; preds = %for.end14.loopexit, %for.cond.preheader
122 br i1 %cmp, label %for.cond5.preheader.lr.ph.1, label %for.end14.1
124 for.cond5.preheader.lr.ph.1: ; preds = %for.end14
125 br label %for.cond5.preheader.1
127 for.cond5.preheader.1: ; preds = %for.cond.loopexit.1, %for.cond5.preheader.lr.ph.1
128 %ca.19.1 = phi i64 [ 0, %for.cond5.preheader.lr.ph.1 ], [ %ca.3.lcssa.1, %for.cond.loopexit.1 ]
129 br i1 true, label %for.cond8.preheader.1, label %for.body7.preheader.1
131 for.body7.preheader.1: ; preds = %for.cond5.preheader.1
132 br label %for.body7.1
134 for.body7.1: ; preds = %for.body7.1, %for.body7.preheader.1
135 %ca.26.1 = phi i64 [ %inc.1, %for.body7.1 ], [ %ca.19.1, %for.body7.preheader.1 ]
136 %inc.1 = add nsw i64 %ca.26.1, 1
137 %arrayidx.1 = getelementptr inbounds double, ptr %bx, i64 %ca.26.1
138 store double 0.000000e+00, ptr %arrayidx.1, align 8
139 br i1 true, label %for.cond8.preheader.loopexit.1, label %for.body7.1
141 for.cond8.preheader.loopexit.1: ; preds = %for.body7.1
142 %inc.lcssa.1 = phi i64 [ %inc.1, %for.body7.1 ]
143 br label %for.cond8.preheader.1
145 for.cond8.preheader.1: ; preds = %for.cond8.preheader.loopexit.1, %for.cond5.preheader.1
146 %ca.2.lcssa.1 = phi i64 [ %ca.19.1, %for.cond5.preheader.1 ], [ %inc.lcssa.1, %for.cond8.preheader.loopexit.1 ]
147 br i1 false, label %for.body10.preheader.1, label %for.cond.loopexit.1
149 for.body10.preheader.1: ; preds = %for.cond8.preheader.1
150 br label %for.body10.1
152 for.body10.1: ; preds = %for.body10.1, %for.body10.preheader.1
153 %ca.37.1 = phi i64 [ %inc11.1, %for.body10.1 ], [ %ca.2.lcssa.1, %for.body10.preheader.1 ]
154 %inc11.1 = add nsw i64 %ca.37.1, 1
155 br i1 false, label %for.body10.1, label %for.cond.loopexit.loopexit.1
157 for.cond.loopexit.loopexit.1: ; preds = %for.body10.1
158 %inc11.lcssa.1 = phi i64 [ %inc11.1, %for.body10.1 ]
159 br label %for.cond.loopexit.1
161 for.cond.loopexit.1: ; preds = %for.cond.loopexit.loopexit.1, %for.cond8.preheader.1
162 %ca.3.lcssa.1 = phi i64 [ %ca.2.lcssa.1, %for.cond8.preheader.1 ], [ %inc11.lcssa.1, %for.cond.loopexit.loopexit.1 ]
163 br i1 %cmp, label %for.cond5.preheader.1, label %for.end14.loopexit.1
165 for.end14.loopexit.1: ; preds = %for.cond.loopexit.1
166 br label %for.end14.1
168 for.end14.1: ; preds = %for.end14.loopexit.1, %for.end14