1; RUN: opt < %s -loop-reduce -lsr-setupcost-depth-limit=1 -S | FileCheck %s 2 3; This test is adapted from the n-body test of the LLVM test-suite: A bug in 4; r345114 caused LSR to generate incorrect code. The test verifies that the 5; induction variable generated for the inner loop depends on the induction 6; variable of the outer loop. 7 8target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 9target triple = "x86_64-unknown-linux-gnu" 10 11%struct.planet.0.3.6.11.12.15.16.17.24.25.26.33.44 = type { double, double, double, double, double, double, double } 12 13; Function Attrs: nounwind uwtable 14define dso_local void @advance(i32 %nbodies, ptr nocapture %bodies) local_unnamed_addr #0 { 15; CHECK-LABEL: @advance( 16; CHECK: for.cond.loopexit: 17; CHECK: [[LSR_IV_NEXT:%.*]] = add i64 [[LSR_IV:%.*]], -1 18; CHECK: br label %for.body 19; CHECK: for.body: 20; CHECK: [[LSR_IV]] = phi i64 [ [[LSR_IV_NEXT]] 21; CHECK: br label %for.body3 22; CHECK: for.body3: 23; CHECK: [[LSR_IV1:%.*]] = phi i64 [ [[LSR_IV_NEXT2:%.*]], %for.body3 ], [ [[LSR_IV]], %for.body ] 24; CHECK: [[LSR_IV_NEXT2]] = add i64 [[LSR_IV1]], -1 25; CHECK: [[EXITCOND:%.*]] = icmp eq i64 [[LSR_IV_NEXT2]], 0 26; CHECK: br i1 [[EXITCOND]], label %for.cond.loopexit, label %for.body3 27; 28entry: 29 %wide.trip.count = zext i32 %nbodies to i64 30 br label %for.body 31 32for.cond.loopexit: ; preds = %for.body3 33 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 34 br label %for.body 35 36for.body: ; preds = %for.cond.loopexit, %entry 37 %indvars.iv = phi i64 [ 1, %entry ], [ %indvars.iv.next, %for.cond.loopexit ] 38 br label %for.body3 39 40for.body3: ; preds = %for.body3, %for.body 41 %indvars.iv98 = phi i64 [ %indvars.iv, %for.body ], [ %indvars.iv.next99, %for.body3 ] 42 %z9 = getelementptr inbounds %struct.planet.0.3.6.11.12.15.16.17.24.25.26.33.44, ptr %bodies, i64 %indvars.iv98, i32 2 43 %tmp = load double, ptr %z9, align 8, !tbaa !0 44 %indvars.iv.next99 = add nuw nsw i64 %indvars.iv98, 1 45 %exitcond = icmp eq i64 %indvars.iv.next99, %wide.trip.count 46 br i1 %exitcond, label %for.cond.loopexit, label %for.body3 47} 48 49attributes #0 = { nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } 50 51!0 = !{!1, !2, i64 16} 52!1 = !{!"planet", !2, i64 0, !2, i64 8, !2, i64 16, !2, i64 24, !2, i64 32, !2, i64 40, !2, i64 48} 53!2 = !{!"double", !3, i64 0} 54!3 = !{!"omnipotent char", !4, i64 0} 55!4 = !{!"Simple C/C++ TBAA"} 56