• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt -basicaa -loop-load-elim -S < %s | FileCheck %s
2
3; In this case the later store forward to the load:
4;
5;   for (unsigned i = 0; i < 100; i++) {
6;     B[i] = A[i] + 1;
7;     A[i+1] = C[i] + 2;
8;     A[i+1] = D[i] + 3;
9;   }
10
11target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
12
13define void @f(i32* noalias nocapture %A, i32* noalias nocapture readonly %B,
14               i32* noalias nocapture %C, i32* noalias nocapture readonly %D,
15               i64 %N) {
16entry:
17; CHECK: %load_initial = load i32, i32* %A
18  br label %for.body
19
20for.body:                                         ; preds = %for.body, %entry
21; CHECK: %store_forwarded = phi i32 [ %load_initial, %entry ], [ %addD, %for.body ]
22  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
23  %arrayidxA = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
24  %loadA = load i32, i32* %arrayidxA, align 4
25; CHECK: %addA = add i32 %store_forwarded, 1
26  %addA = add i32 %loadA, 1
27
28  %arrayidxB = getelementptr inbounds i32, i32* %B, i64 %indvars.iv
29  store i32 %addA, i32* %arrayidxB, align 4
30
31  %arrayidxC = getelementptr inbounds i32, i32* %C, i64 %indvars.iv
32  %loadC = load i32, i32* %arrayidxC, align 4
33  %addC = add i32 %loadC, 2
34  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
35  %arrayidxA_next = getelementptr inbounds i32, i32* %A, i64 %indvars.iv.next
36  store i32 %addC, i32* %arrayidxA_next, align 4
37
38  %arrayidxD = getelementptr inbounds i32, i32* %D, i64 %indvars.iv
39  %loadD = load i32, i32* %arrayidxD, align 4
40  %addD = add i32 %loadD, 3
41  store i32 %addD, i32* %arrayidxA_next, align 4
42
43  %exitcond = icmp eq i64 %indvars.iv.next, %N
44  br i1 %exitcond, label %for.end, label %for.body
45
46for.end:                                          ; preds = %for.body
47  ret void
48}
49