80 lines · plain
1; RUN: opt < %s -S -passes=loop-unroll -unroll-max-iteration-count-to-analyze=100 -unroll-threshold=10 -unroll-max-percent-threshold-boost=200 | FileCheck %s2; RUN: opt < %s -S -passes='require<opt-remark-emit>,loop(loop-unroll-full)' -unroll-max-iteration-count-to-analyze=100 -unroll-threshold=10 -unroll-max-percent-threshold-boost=200 | FileCheck %s3target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"4 5@known_constant = internal unnamed_addr constant [10 x i32] [i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1], align 166 7; If we can figure out result of comparison on each iteration, we can resolve8; the depending branch. That means, that the unrolled version of the loop would9; have less code, because we don't need not-taken basic blocks there.10; This test checks that this is taken into consideration.11; We expect this loop to be unrolled, because the most complicated part of its12; body (if.then block) is never actually executed.13; CHECK-LABEL: @branch_folded14; CHECK-NOT: br i1 %15; CHECK: ret i3216define i32 @branch_folded(ptr noalias nocapture readonly %b) {17entry:18 br label %for.body19 20for.body: ; preds = %for.inc, %entry21 %iv.0 = phi i64 [ 0, %entry ], [ %iv.1, %for.inc ]22 %r.0 = phi i32 [ 0, %entry ], [ %r.1, %for.inc ]23 %arrayidx1 = getelementptr inbounds [10 x i32], ptr @known_constant, i64 0, i64 %iv.024 %x1 = load i32, ptr %arrayidx1, align 425 %cmp = icmp eq i32 %x1, 026 %iv.1 = add nuw nsw i64 %iv.0, 127 br i1 %cmp, label %if.then, label %for.inc28 29if.then: ; preds = %for.body30 %arrayidx2 = getelementptr inbounds i32, ptr %b, i64 %iv.031 %x2 = load i32, ptr %arrayidx2, align 432 %add = add nsw i32 %x2, %r.033 br label %for.inc34 35for.inc: ; preds = %for.body, %if.then36 %r.1 = phi i32 [ %add, %if.then ], [ %x1, %for.body ]37 %exitcond = icmp eq i64 %iv.1, 1038 br i1 %exitcond, label %for.end, label %for.body39 40for.end: ; preds = %for.inc41 ret i32 %r.142}43 44; Check that we don't crash when we analyze icmp with pointer-typed IV and a45; pointer.46; CHECK-LABEL: @ptr_cmp_crash47; CHECK: ret void48define void @ptr_cmp_crash() {49entry:50 br label %while.body51 52while.body:53 %iv.0 = phi ptr [ @known_constant, %entry ], [ %iv.1, %while.body ]54 %iv.1 = getelementptr inbounds i32, ptr %iv.0, i64 155 %exitcond = icmp eq ptr %iv.1, getelementptr inbounds ([10 x i32], ptr @known_constant, i64 0, i64 9)56 br i1 %exitcond, label %loop.exit, label %while.body57 58loop.exit:59 ret void60}61 62; Check that we don't crash when we analyze ptrtoint cast.63; CHECK-LABEL: @ptrtoint_cast_crash64; CHECK: ret void65define void @ptrtoint_cast_crash(ptr %a) {66entry:67 %limit = getelementptr i8, ptr %a, i64 51268 br label %loop.body69 70loop.body:71 %iv.0 = phi ptr [ %a, %entry ], [ %iv.1, %loop.body ]72 %cast = ptrtoint ptr %iv.0 to i6473 %iv.1 = getelementptr inbounds i8, ptr %iv.0, i64 174 %exitcond = icmp ne ptr %iv.1, %limit75 br i1 %exitcond, label %loop.body, label %loop.exit76 77loop.exit:78 ret void79}80