66 lines · plain
1; RUN: opt -mtriple=x86_64-unknown-linux-gnu -loop-reduce -lsr-insns-cost=false -S < %s | FileCheck %s2; Check LSR formula canonicalization will put loop invariant regs before3; induction variable of current loop, so exprs involving loop invariant regs4; can be promoted outside of current loop.5 6target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"7 8define void @foo(i32 %size, i32 %nsteps, ptr nocapture %maxarray, ptr nocapture readnone %buffer, i32 %init) local_unnamed_addr #0 {9entry:10 %cmp25 = icmp sgt i32 %nsteps, 011 br i1 %cmp25, label %for.cond1.preheader.lr.ph, label %for.end1212 13for.cond1.preheader.lr.ph: ; preds = %entry14 %cmp223 = icmp sgt i32 %size, 115 %t0 = sext i32 %init to i6416 %wide.trip.count = zext i32 %size to i6417 %wide.trip.count31 = zext i32 %nsteps to i6418 br label %for.cond1.preheader19 20for.cond1.preheader: ; preds = %for.inc10, %for.cond1.preheader.lr.ph21 %indvars.iv28 = phi i64 [ 0, %for.cond1.preheader.lr.ph ], [ %indvars.iv.next29, %for.inc10 ]22 br i1 %cmp223, label %for.body3.lr.ph, label %for.inc1023 24for.body3.lr.ph: ; preds = %for.cond1.preheader25 %t1 = add nsw i64 %indvars.iv28, %t026 %t2 = trunc i64 %indvars.iv28 to i827 br label %for.body328 29; Make sure loop invariant items are grouped together so that load address can30; be represented in one getelementptr.31; CHECK-LABEL: for.body3:32; CHECK-NEXT: [[LSR:%[^,]+]] = phi i64 [ 1, %for.body3.lr.ph ], [ {{.*}}, %for.body3 ]33; CHECK-NOT: = phi i6434; CHECK-NEXT: [[LOADADDR:%[^,]+]] = getelementptr i8, ptr {{.*}}, i64 [[LSR]]35; CHECK-NEXT: = load i8, ptr [[LOADADDR]], align 136; CHECK: br i1 %exitcond, label %for.inc10.loopexit, label %for.body337 38for.body3: ; preds = %for.body3, %for.body3.lr.ph39 %indvars.iv = phi i64 [ 1, %for.body3.lr.ph ], [ %indvars.iv.next, %for.body3 ]40 %t5 = trunc i64 %indvars.iv to i841 %t3 = add nsw i64 %t1, %indvars.iv42 %arrayidx = getelementptr inbounds i8, ptr %maxarray, i64 %t343 %t4 = load i8, ptr %arrayidx, align 144 %add5 = add i8 %t4, %t545 %add6 = add i8 %add5, %t246 %arrayidx9 = getelementptr inbounds i8, ptr %maxarray, i64 %indvars.iv47 store i8 %add6, ptr %arrayidx9, align 148 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 149 %exitcond = icmp eq i64 %indvars.iv.next, %wide.trip.count50 br i1 %exitcond, label %for.inc10.loopexit, label %for.body351 52for.inc10.loopexit: ; preds = %for.body353 br label %for.inc1054 55for.inc10: ; preds = %for.inc10.loopexit, %for.cond1.preheader56 %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, 157 %exitcond32 = icmp eq i64 %indvars.iv.next29, %wide.trip.count3158 br i1 %exitcond32, label %for.end12.loopexit, label %for.cond1.preheader59 60for.end12.loopexit: ; preds = %for.inc1061 br label %for.end1262 63for.end12: ; preds = %for.end12.loopexit, %entry64 ret void65}66