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