1; RUN: opt < %s -S -loop-unroll -unroll-max-iteration-count-to-analyze=100 -unroll-dynamic-cost-savings-discount=1000 -unroll-threshold=10 -unroll-percent-dynamic-cost-saved-threshold=60 | FileCheck %s 2target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" 3 4@known_constant = internal unnamed_addr constant [10 x i32] [i32 0, i32 0, i32 0, i32 0, i32 1, i32 0, i32 0, i32 0, i32 0, i32 0], align 16 5 6; If a load becomes a constant after loop unrolling, we sometimes can simplify 7; CFG. This test verifies that we handle such cases. 8; After one operand in an instruction is constant-folded and the 9; instruction is simplified, the other operand might become dead. 10; In this test we have:: 11; for i in 1..10: 12; r += A[i] * B[i] 13; A[i] is 0 almost at every iteration, so there is no need in loading B[i] at 14; all. 15 16 17; CHECK-LABEL: @unroll_dce 18; CHECK-NOT: br i1 %exitcond, label %for.end, label %for.body 19define i32 @unroll_dce(i32* noalias nocapture readonly %b) { 20entry: 21 br label %for.body 22 23for.body: ; preds = %for.body, %entry 24 %iv.0 = phi i64 [ 0, %entry ], [ %iv.1, %for.body ] 25 %r.0 = phi i32 [ 0, %entry ], [ %r.1, %for.body ] 26 %arrayidx1 = getelementptr inbounds [10 x i32], [10 x i32]* @known_constant, i64 0, i64 %iv.0 27 %x1 = load i32, i32* %arrayidx1, align 4 28 %arrayidx2 = getelementptr inbounds i32, i32* %b, i64 %iv.0 29 %x2 = load i32, i32* %arrayidx2, align 4 30 %mul = mul i32 %x1, %x2 31 %r.1 = add i32 %mul, %r.0 32 %iv.1 = add nuw nsw i64 %iv.0, 1 33 %exitcond = icmp eq i64 %iv.1, 10 34 br i1 %exitcond, label %for.end, label %for.body 35 36for.end: ; preds = %for.body 37 ret i32 %r.1 38} 39