Adam Nemet | bd861ac | 2016-06-28 04:02:47 +0000 | [diff] [blame] | 1 | ; RUN: opt -S -loop-load-elim < %s | FileCheck %s |
| 2 | |
| 3 | ; We can't hoist conditional loads to the preheader for the initial value. |
| 4 | ; E.g. in the loop below we'd access array[-1] if we did: |
| 5 | ; |
| 6 | ; for(int i = 0 ; i < n ; i++ ) |
| 7 | ; array[i] = ( i > 0 ? array[i - 1] : 0 ) + 4; |
| 8 | |
| 9 | target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" |
| 10 | target triple = "x86_64-apple-macosx10.11.0" |
| 11 | |
| 12 | define void @f(i32* %array, i32 %n) { |
| 13 | entry: |
| 14 | %cmp10 = icmp sgt i32 %n, 0 |
| 15 | br i1 %cmp10, label %for.body, label %for.cond.cleanup |
| 16 | |
| 17 | for.cond.cleanup: ; preds = %cond.end, %entry |
| 18 | ret void |
| 19 | |
| 20 | for.body: ; preds = %entry, %cond.end |
| 21 | %indvars.iv = phi i64 [ %indvars.iv.next, %cond.end ], [ 0, %entry ] |
| 22 | ; CHECK-NOT: %store_forwarded = phi |
| 23 | %cmp1 = icmp sgt i64 %indvars.iv, 0 |
| 24 | br i1 %cmp1, label %cond.true, label %cond.end |
| 25 | |
| 26 | cond.true: ; preds = %for.body |
| 27 | %0 = add nsw i64 %indvars.iv, -1 |
| 28 | %arrayidx = getelementptr inbounds i32, i32* %array, i64 %0 |
| 29 | %1 = load i32, i32* %arrayidx, align 4 |
| 30 | br label %cond.end |
| 31 | |
| 32 | cond.end: ; preds = %for.body, %cond.true |
| 33 | %cond = phi i32 [ %1, %cond.true ], [ 0, %for.body ] |
| 34 | ; CHECK: %cond = phi i32 [ %1, %cond.true ], [ 0, %for.body ] |
| 35 | %add = add nsw i32 %cond, 4 |
| 36 | %arrayidx3 = getelementptr inbounds i32, i32* %array, i64 %indvars.iv |
| 37 | store i32 %add, i32* %arrayidx3, align 4 |
| 38 | %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 |
| 39 | %lftr.wideiv = trunc i64 %indvars.iv.next to i32 |
| 40 | %exitcond = icmp eq i32 %lftr.wideiv, %n |
| 41 | br i1 %exitcond, label %for.cond.cleanup, label %for.body |
| 42 | } |