Michael Zolotukhin | fc314be | 2015-09-16 03:25:09 +0000 | [diff] [blame^] | 1 | ; RUN: opt < %s -S -loop-unroll -unroll-max-iteration-count-to-analyze=1000 -unroll-threshold=10 -unroll-percent-dynamic-cost-saved-threshold=50 -unroll-dynamic-cost-savings-discount=90 | FileCheck %s |
| 2 | target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" |
| 3 | |
| 4 | ; Though @unknown_global is initialized with constant values, we can't consider |
| 5 | ; it as a constant, so we shouldn't unroll the loop. |
| 6 | ; CHECK: %array_const_idx = getelementptr inbounds [9 x i32], [9 x i32]* @unknown_global, i64 0, i64 %iv |
| 7 | @unknown_global = internal unnamed_addr global [9 x i32] [i32 0, i32 -1, i32 0, i32 -1, i32 5, i32 -1, i32 0, i32 -1, i32 0], align 16 |
| 8 | |
| 9 | define i32 @foo(i32* noalias nocapture readonly %src) { |
| 10 | entry: |
| 11 | br label %loop |
| 12 | |
| 13 | loop: ; preds = %loop, %entry |
| 14 | %iv = phi i64 [ 0, %entry ], [ %inc, %loop ] |
| 15 | %r = phi i32 [ 0, %entry ], [ %add, %loop ] |
| 16 | %arrayidx = getelementptr inbounds i32, i32* %src, i64 %iv |
| 17 | %src_element = load i32, i32* %arrayidx, align 4 |
| 18 | %array_const_idx = getelementptr inbounds [9 x i32], [9 x i32]* @unknown_global, i64 0, i64 %iv |
| 19 | %const_array_element = load i32, i32* %array_const_idx, align 4 |
| 20 | %mul = mul nsw i32 %src_element, %const_array_element |
| 21 | %add = add nsw i32 %mul, %r |
| 22 | %inc = add nuw nsw i64 %iv, 1 |
| 23 | %exitcond86.i = icmp eq i64 %inc, 9 |
| 24 | br i1 %exitcond86.i, label %loop.end, label %loop |
| 25 | |
| 26 | loop.end: ; preds = %loop |
| 27 | %r.lcssa = phi i32 [ %r, %loop ] |
| 28 | ret i32 %r.lcssa |
| 29 | } |