aboutsummaryrefslogtreecommitdiff
path: root/test/Transforms/LoopLoadElim/multiple-stores-same-block.ll
diff options
context:
space:
mode:
Diffstat (limited to 'test/Transforms/LoopLoadElim/multiple-stores-same-block.ll')
-rw-r--r--test/Transforms/LoopLoadElim/multiple-stores-same-block.ll48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/Transforms/LoopLoadElim/multiple-stores-same-block.ll b/test/Transforms/LoopLoadElim/multiple-stores-same-block.ll
new file mode 100644
index 000000000000..b0c0f3dee86e
--- /dev/null
+++ b/test/Transforms/LoopLoadElim/multiple-stores-same-block.ll
@@ -0,0 +1,48 @@
+; RUN: opt -basicaa -loop-load-elim -S < %s | FileCheck %s
+
+; In this case the later store forward to the load:
+;
+; for (unsigned i = 0; i < 100; i++) {
+; B[i] = A[i] + 1;
+; A[i+1] = C[i] + 2;
+; A[i+1] = D[i] + 3;
+; }
+
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @f(i32* noalias nocapture %A, i32* noalias nocapture readonly %B,
+ i32* noalias nocapture %C, i32* noalias nocapture readonly %D,
+ i64 %N) {
+entry:
+; CHECK: %load_initial = load i32, i32* %A
+ br label %for.body
+
+for.body: ; preds = %for.body, %entry
+; CHECK: %store_forwarded = phi i32 [ %load_initial, %entry ], [ %addD, %for.body ]
+ %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
+ %arrayidxA = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
+ %loadA = load i32, i32* %arrayidxA, align 4
+; CHECK: %addA = add i32 %store_forwarded, 1
+ %addA = add i32 %loadA, 1
+
+ %arrayidxB = getelementptr inbounds i32, i32* %B, i64 %indvars.iv
+ store i32 %addA, i32* %arrayidxB, align 4
+
+ %arrayidxC = getelementptr inbounds i32, i32* %C, i64 %indvars.iv
+ %loadC = load i32, i32* %arrayidxC, align 4
+ %addC = add i32 %loadC, 2
+ %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+ %arrayidxA_next = getelementptr inbounds i32, i32* %A, i64 %indvars.iv.next
+ store i32 %addC, i32* %arrayidxA_next, align 4
+
+ %arrayidxD = getelementptr inbounds i32, i32* %D, i64 %indvars.iv
+ %loadD = load i32, i32* %arrayidxD, align 4
+ %addD = add i32 %loadD, 3
+ store i32 %addD, i32* %arrayidxA_next, align 4
+
+ %exitcond = icmp eq i64 %indvars.iv.next, %N
+ br i1 %exitcond, label %for.end, label %for.body
+
+for.end: ; preds = %for.body
+ ret void
+}