1 ; RUN: opt -S -analyze -scalar-evolution -loop-deletion -scalar-evolution -verify-scev < %s -enable-new-pm=0 | FileCheck %s --check-prefix=SCEV-EXPRS
2 ; RUN: opt -S -passes='print<scalar-evolution>,loop-deletion,print<scalar-evolution>' -verify-scev < %s 2>&1 | FileCheck %s --check-prefix=SCEV-EXPRS
3 ; RUN: opt -S -loop-deletion < %s | FileCheck %s --check-prefix=IR-AFTER-TRANSFORM
4 ; RUN: opt -S -indvars -loop-deletion -indvars < %s | FileCheck %s --check-prefix=ORIGINAL-CRASH
6 ; Checking for a crash. Loop-deletion would change the loop
7 ; disposition of an instruction, but not update SCEV.
9 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
10 target triple = "x86_64-apple-macosx10.11.0"
12 define void @pr27570() {
13 ; IR-AFTER-TRANSFORM-LABEL: @pr27570(
14 ; ORIGINAL-CRASH: @pr27570(
18 for.cond: ; preds = %for.cond14, %entry
19 %f.0 = phi i32 [ 20, %entry ], [ 0, %for.cond14 ]
22 for.body: ; preds = %for.inc11, %for.cond
23 ; IR-AFTER-TRANSFORM: for.body:
24 ; IR-AFTER-TRANSFORM: %cmp = icmp eq i32 %val, -1
25 ; IR-AFTER-TRANSFORM: %conv7 = zext i1 %cmp to i32
26 ; IR-AFTER-TRANSFORM: for.body6:
28 ; SCEV-EXPRS: %conv7 = zext i1 %cmp to i32
29 ; SCEV-EXPRS: %conv7 = zext i1 %cmp to i32
30 ; SCEV-EXPRS-NEXT: --> {{.*}} LoopDispositions: { %for.body: Variant, %for.cond: Variant, %for.body6: Invariant }
31 %val = phi i32 [ -20, %for.cond ], [ %inc12, %for.inc11 ]
32 %g.040 = phi i32 [ -20, %for.cond ], [ %and.lcssa, %for.inc11 ]
35 for.body6: ; preds = %for.body6, %for.body
36 %h.039 = phi i32 [ 1, %for.body ], [ %inc, %for.body6 ]
37 %g.138 = phi i32 [ %g.040, %for.body ], [ %and, %for.body6 ]
38 %cmp = icmp eq i32 %val, -1
39 %conv7 = zext i1 %cmp to i32
40 %add.i = add nsw i32 %conv7, %h.039
41 %sext = shl i32 %add.i, 24
42 %conv8 = ashr exact i32 %sext, 24
43 %cmp9 = icmp eq i32 %conv8, %f.0
44 %conv10 = zext i1 %cmp9 to i32
45 %and = and i32 %conv10, %g.138
46 %inc = add i32 %h.039, 1
47 %exit = icmp eq i32 %inc, 20000
48 br i1 %exit, label %for.inc11, label %for.body6
50 for.inc11: ; preds = %for.body6
51 %and.lcssa = phi i32 [ %and, %for.body6 ]
52 call void @sideeffect(i32 %and.lcssa)
53 %inc12 = add nsw i32 %val, 1
54 %tobool = icmp eq i32 %inc12, 0
55 br i1 %tobool, label %for.cond14, label %for.body
57 for.cond14: ; preds = %for.cond14, %for.inc11
58 br i1 undef, label %for.cond, label %for.cond14
61 declare void @sideeffect(i32)
63 ; LoopDeletion removes the loop %for.body7.1. Make sure %inc.lcssa.1 in the loop
64 ; exit block is correctly invalidated.
66 define void @test2(double* %bx, i64 %by) local_unnamed_addr align 2 {
67 ; IR-AFTER-TRANSFORM-LABEL: @test2(
68 ; IR-AFTER-TRANSFORM-NOT: for.body7.1:
70 ; SCEV-EXPRS-LABEL: test2
71 ; SCEV-EXPRS: %inc.lcssa.1 = phi i64 [ undef, %for.body7.preheader.1 ]
72 ; SCEV-EXPRS-NEXT: --> undef
74 %cmp = icmp sgt i64 %by, 0
75 br label %for.cond.preheader
77 for.cond.preheader: ; preds = %entry
78 br i1 %cmp, label %for.cond5.preheader.lr.ph, label %for.end14
80 for.cond5.preheader.lr.ph: ; preds = %for.cond.preheader
81 br label %for.cond5.preheader
83 for.cond.loopexit.loopexit: ; preds = %for.body10
84 %inc11.lcssa = phi i64 [ %inc11, %for.body10 ]
85 br label %for.cond.loopexit
87 for.cond.loopexit: ; preds = %for.cond8.preheader, %for.cond.loopexit.loopexit
88 %ca.3.lcssa = phi i64 [ %ca.2.lcssa, %for.cond8.preheader ], [ %inc11.lcssa, %for.cond.loopexit.loopexit ]
89 br i1 %cmp, label %for.cond5.preheader, label %for.end14.loopexit
91 for.cond5.preheader: ; preds = %for.cond.loopexit, %for.cond5.preheader.lr.ph
92 %ca.19 = phi i64 [ 0, %for.cond5.preheader.lr.ph ], [ %ca.3.lcssa, %for.cond.loopexit ]
93 br i1 false, label %for.cond8.preheader, label %for.body7.preheader
95 for.body7.preheader: ; preds = %for.cond5.preheader
98 for.cond8.preheader.loopexit: ; preds = %for.body7
99 %inc.lcssa = phi i64 [ %inc, %for.body7 ]
100 br label %for.cond8.preheader
102 for.cond8.preheader: ; preds = %for.cond8.preheader.loopexit, %for.cond5.preheader
103 %ca.2.lcssa = phi i64 [ %ca.19, %for.cond5.preheader ], [ %inc.lcssa, %for.cond8.preheader.loopexit ]
104 br i1 true, label %for.body10.preheader, label %for.cond.loopexit
106 for.body10.preheader: ; preds = %for.cond8.preheader
109 for.body7: ; preds = %for.body7, %for.body7.preheader
110 %ca.26 = phi i64 [ %inc, %for.body7 ], [ %ca.19, %for.body7.preheader ]
111 %inc = add nsw i64 %ca.26, 1
112 %arrayidx = getelementptr inbounds double, double* %bx, i64 %ca.26
113 store double 0.000000e+00, double* %arrayidx, align 8
114 br i1 false, label %for.cond8.preheader.loopexit, label %for.body7
116 for.body10: ; preds = %for.body10, %for.body10.preheader
117 %ca.37 = phi i64 [ %inc11, %for.body10 ], [ %ca.2.lcssa, %for.body10.preheader ]
118 %inc11 = add nsw i64 %ca.37, 1
119 br i1 true, label %for.body10, label %for.cond.loopexit.loopexit
121 for.end14.loopexit: ; preds = %for.cond.loopexit
124 for.end14: ; preds = %for.end14.loopexit, %for.cond.preheader
125 br i1 %cmp, label %for.cond5.preheader.lr.ph.1, label %for.end14.1
127 for.cond5.preheader.lr.ph.1: ; preds = %for.end14
128 br label %for.cond5.preheader.1
130 for.cond5.preheader.1: ; preds = %for.cond.loopexit.1, %for.cond5.preheader.lr.ph.1
131 %ca.19.1 = phi i64 [ 0, %for.cond5.preheader.lr.ph.1 ], [ %ca.3.lcssa.1, %for.cond.loopexit.1 ]
132 br i1 true, label %for.cond8.preheader.1, label %for.body7.preheader.1
134 for.body7.preheader.1: ; preds = %for.cond5.preheader.1
135 br label %for.body7.1
137 for.body7.1: ; preds = %for.body7.1, %for.body7.preheader.1
138 %ca.26.1 = phi i64 [ %inc.1, %for.body7.1 ], [ %ca.19.1, %for.body7.preheader.1 ]
139 %inc.1 = add nsw i64 %ca.26.1, 1
140 %arrayidx.1 = getelementptr inbounds double, double* %bx, i64 %ca.26.1
141 store double 0.000000e+00, double* %arrayidx.1, align 8
142 br i1 true, label %for.cond8.preheader.loopexit.1, label %for.body7.1
144 for.cond8.preheader.loopexit.1: ; preds = %for.body7.1
145 %inc.lcssa.1 = phi i64 [ %inc.1, %for.body7.1 ]
146 br label %for.cond8.preheader.1
148 for.cond8.preheader.1: ; preds = %for.cond8.preheader.loopexit.1, %for.cond5.preheader.1
149 %ca.2.lcssa.1 = phi i64 [ %ca.19.1, %for.cond5.preheader.1 ], [ %inc.lcssa.1, %for.cond8.preheader.loopexit.1 ]
150 br i1 false, label %for.body10.preheader.1, label %for.cond.loopexit.1
152 for.body10.preheader.1: ; preds = %for.cond8.preheader.1
153 br label %for.body10.1
155 for.body10.1: ; preds = %for.body10.1, %for.body10.preheader.1
156 %ca.37.1 = phi i64 [ %inc11.1, %for.body10.1 ], [ %ca.2.lcssa.1, %for.body10.preheader.1 ]
157 %inc11.1 = add nsw i64 %ca.37.1, 1
158 br i1 false, label %for.body10.1, label %for.cond.loopexit.loopexit.1
160 for.cond.loopexit.loopexit.1: ; preds = %for.body10.1
161 %inc11.lcssa.1 = phi i64 [ %inc11.1, %for.body10.1 ]
162 br label %for.cond.loopexit.1
164 for.cond.loopexit.1: ; preds = %for.cond.loopexit.loopexit.1, %for.cond8.preheader.1
165 %ca.3.lcssa.1 = phi i64 [ %ca.2.lcssa.1, %for.cond8.preheader.1 ], [ %inc11.lcssa.1, %for.cond.loopexit.loopexit.1 ]
166 br i1 %cmp, label %for.cond5.preheader.1, label %for.end14.loopexit.1
168 for.end14.loopexit.1: ; preds = %for.cond.loopexit.1
169 br label %for.end14.1
171 for.end14.1: ; preds = %for.end14.loopexit.1, %for.end14