1 ; RUN: opt -basicaa -loop-load-elim -S < %s | FileCheck %s
3 ; In this case the later store forward to the load:
5 ; for (unsigned i = 0; i < 100; i++) {
11 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
13 define void @f(i32* noalias nocapture %A, i32* noalias nocapture readonly %B,
14 i32* noalias nocapture %C, i32* noalias nocapture readonly %D,
17 ; CHECK: %load_initial = load i32, i32* %A
20 for.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
28 %arrayidxB = getelementptr inbounds i32, i32* %B, i64 %indvars.iv
29 store i32 %addA, i32* %arrayidxB, align 4
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
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
43 %exitcond = icmp eq i64 %indvars.iv.next, %N
44 br i1 %exitcond, label %for.end, label %for.body
46 for.end: ; preds = %for.body