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 5 6; Checking for a crash. Loop-deletion would change the loop 7; disposition of an instruction, but not update SCEV. 8 9target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" 10target triple = "x86_64-apple-macosx10.11.0" 11 12define void @pr27570() { 13; IR-AFTER-TRANSFORM-LABEL: @pr27570( 14; ORIGINAL-CRASH: @pr27570( 15entry: 16 br label %for.cond 17 18for.cond: ; preds = %for.cond14, %entry 19 %f.0 = phi i32 [ 20, %entry ], [ 0, %for.cond14 ] 20 br label %for.body 21 22for.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: 27 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 ] 33 br label %for.body6 34 35for.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 br i1 undef, label %for.inc11, label %for.body6 48 49for.inc11: ; preds = %for.body6 50 %and.lcssa = phi i32 [ %and, %for.body6 ] 51 %inc12 = add nsw i32 %val, 1 52 %tobool = icmp eq i32 %inc12, 0 53 br i1 %tobool, label %for.cond14, label %for.body 54 55for.cond14: ; preds = %for.cond14, %for.inc11 56 br i1 undef, label %for.cond, label %for.cond14 57} 58 59; LoopDeletion removes the loop %for.body7.1. Make sure %inc.lcssa.1 in the loop 60; exit block is correctly invalidated. 61 62define void @test2(double* %bx, i64 %by) local_unnamed_addr align 2 { 63; IR-AFTER-TRANSFORM-LABEL: @test2( 64; IR-AFTER-TRANSFORM-NOT: for.body7.1: 65 66; SCEV-EXPRS-LABEL: test2 67; SCEV-EXPRS: %inc.lcssa.1 = phi i64 [ undef, %for.body7.preheader.1 ] 68; SCEV-EXPRS-NEXT: --> undef 69entry: 70 %cmp = icmp sgt i64 %by, 0 71 br label %for.cond.preheader 72 73for.cond.preheader: ; preds = %entry 74 br i1 %cmp, label %for.cond5.preheader.lr.ph, label %for.end14 75 76for.cond5.preheader.lr.ph: ; preds = %for.cond.preheader 77 br label %for.cond5.preheader 78 79for.cond.loopexit.loopexit: ; preds = %for.body10 80 %inc11.lcssa = phi i64 [ %inc11, %for.body10 ] 81 br label %for.cond.loopexit 82 83for.cond.loopexit: ; preds = %for.cond8.preheader, %for.cond.loopexit.loopexit 84 %ca.3.lcssa = phi i64 [ %ca.2.lcssa, %for.cond8.preheader ], [ %inc11.lcssa, %for.cond.loopexit.loopexit ] 85 br i1 %cmp, label %for.cond5.preheader, label %for.end14.loopexit 86 87for.cond5.preheader: ; preds = %for.cond.loopexit, %for.cond5.preheader.lr.ph 88 %ca.19 = phi i64 [ 0, %for.cond5.preheader.lr.ph ], [ %ca.3.lcssa, %for.cond.loopexit ] 89 br i1 false, label %for.cond8.preheader, label %for.body7.preheader 90 91for.body7.preheader: ; preds = %for.cond5.preheader 92 br label %for.body7 93 94for.cond8.preheader.loopexit: ; preds = %for.body7 95 %inc.lcssa = phi i64 [ %inc, %for.body7 ] 96 br label %for.cond8.preheader 97 98for.cond8.preheader: ; preds = %for.cond8.preheader.loopexit, %for.cond5.preheader 99 %ca.2.lcssa = phi i64 [ %ca.19, %for.cond5.preheader ], [ %inc.lcssa, %for.cond8.preheader.loopexit ] 100 br i1 true, label %for.body10.preheader, label %for.cond.loopexit 101 102for.body10.preheader: ; preds = %for.cond8.preheader 103 br label %for.body10 104 105for.body7: ; preds = %for.body7, %for.body7.preheader 106 %ca.26 = phi i64 [ %inc, %for.body7 ], [ %ca.19, %for.body7.preheader ] 107 %inc = add nsw i64 %ca.26, 1 108 %arrayidx = getelementptr inbounds double, double* %bx, i64 %ca.26 109 store double 0.000000e+00, double* %arrayidx, align 8 110 br i1 false, label %for.cond8.preheader.loopexit, label %for.body7 111 112for.body10: ; preds = %for.body10, %for.body10.preheader 113 %ca.37 = phi i64 [ %inc11, %for.body10 ], [ %ca.2.lcssa, %for.body10.preheader ] 114 %inc11 = add nsw i64 %ca.37, 1 115 br i1 true, label %for.body10, label %for.cond.loopexit.loopexit 116 117for.end14.loopexit: ; preds = %for.cond.loopexit 118 br label %for.end14 119 120for.end14: ; preds = %for.end14.loopexit, %for.cond.preheader 121 br i1 %cmp, label %for.cond5.preheader.lr.ph.1, label %for.end14.1 122 123for.cond5.preheader.lr.ph.1: ; preds = %for.end14 124 br label %for.cond5.preheader.1 125 126for.cond5.preheader.1: ; preds = %for.cond.loopexit.1, %for.cond5.preheader.lr.ph.1 127 %ca.19.1 = phi i64 [ 0, %for.cond5.preheader.lr.ph.1 ], [ %ca.3.lcssa.1, %for.cond.loopexit.1 ] 128 br i1 true, label %for.cond8.preheader.1, label %for.body7.preheader.1 129 130for.body7.preheader.1: ; preds = %for.cond5.preheader.1 131 br label %for.body7.1 132 133for.body7.1: ; preds = %for.body7.1, %for.body7.preheader.1 134 %ca.26.1 = phi i64 [ %inc.1, %for.body7.1 ], [ %ca.19.1, %for.body7.preheader.1 ] 135 %inc.1 = add nsw i64 %ca.26.1, 1 136 %arrayidx.1 = getelementptr inbounds double, double* %bx, i64 %ca.26.1 137 store double 0.000000e+00, double* %arrayidx.1, align 8 138 br i1 true, label %for.cond8.preheader.loopexit.1, label %for.body7.1 139 140for.cond8.preheader.loopexit.1: ; preds = %for.body7.1 141 %inc.lcssa.1 = phi i64 [ %inc.1, %for.body7.1 ] 142 br label %for.cond8.preheader.1 143 144for.cond8.preheader.1: ; preds = %for.cond8.preheader.loopexit.1, %for.cond5.preheader.1 145 %ca.2.lcssa.1 = phi i64 [ %ca.19.1, %for.cond5.preheader.1 ], [ %inc.lcssa.1, %for.cond8.preheader.loopexit.1 ] 146 br i1 false, label %for.body10.preheader.1, label %for.cond.loopexit.1 147 148for.body10.preheader.1: ; preds = %for.cond8.preheader.1 149 br label %for.body10.1 150 151for.body10.1: ; preds = %for.body10.1, %for.body10.preheader.1 152 %ca.37.1 = phi i64 [ %inc11.1, %for.body10.1 ], [ %ca.2.lcssa.1, %for.body10.preheader.1 ] 153 %inc11.1 = add nsw i64 %ca.37.1, 1 154 br i1 false, label %for.body10.1, label %for.cond.loopexit.loopexit.1 155 156for.cond.loopexit.loopexit.1: ; preds = %for.body10.1 157 %inc11.lcssa.1 = phi i64 [ %inc11.1, %for.body10.1 ] 158 br label %for.cond.loopexit.1 159 160for.cond.loopexit.1: ; preds = %for.cond.loopexit.loopexit.1, %for.cond8.preheader.1 161 %ca.3.lcssa.1 = phi i64 [ %ca.2.lcssa.1, %for.cond8.preheader.1 ], [ %inc11.lcssa.1, %for.cond.loopexit.loopexit.1 ] 162 br i1 %cmp, label %for.cond5.preheader.1, label %for.end14.loopexit.1 163 164for.end14.loopexit.1: ; preds = %for.cond.loopexit.1 165 br label %for.end14.1 166 167for.end14.1: ; preds = %for.end14.loopexit.1, %for.end14 168 ret void 169} 170