64 lines · plain
1; RUN: opt -passes=loop-load-elim -S < %s | FileCheck %s2 3; Simple st->ld forwarding derived from a lexical backward dep.4;5; for (unsigned i = 0; i < 100; i++)6; A[i+1] = A[i] + B[i];7 8target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"9 10define void @f(ptr noalias nocapture %A, ptr noalias nocapture readonly %B, i64 %N) {11entry:12; CHECK: %load_initial = load i32, ptr %A13 br label %for.body14 15for.body: ; preds = %for.body, %entry16; CHECK: %store_forwarded = phi i32 [ %load_initial, %entry ], [ %add, %for.body ]17 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]18 %arrayidx = getelementptr inbounds i32, ptr %A, i64 %indvars.iv19 %load = load i32, ptr %arrayidx, align 420 %arrayidx2 = getelementptr inbounds i32, ptr %B, i64 %indvars.iv21 %load_1 = load i32, ptr %arrayidx2, align 422; CHECK: %add = add i32 %load_1, %store_forwarded23 %add = add i32 %load_1, %load24 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 125 %arrayidx_next = getelementptr inbounds i32, ptr %A, i64 %indvars.iv.next26 store i32 %add, ptr %arrayidx_next, align 427 %exitcond = icmp eq i64 %indvars.iv.next, %N28 br i1 %exitcond, label %for.end, label %for.body29 30for.end: ; preds = %for.body31 ret void32}33 34; Same but loop is descending.35;36; for (unsigned i = N; i > 0; i--)37; A[i-1] = A[i] + B[i];38define void @g(ptr noalias nocapture %A, ptr noalias nocapture readonly %B, i64 %N) {39entry:40; CHECK: %0 = shl i64 %N, 241; CHECK: %scevgep = getelementptr i8, ptr %A, i64 %042; CHECK: %load_initial = load i32, ptr %scevgep, align 443 br label %for.body44 45for.body: ; preds = %for.body, %entry46; CHECK: %store_forwarded = phi i32 [ %load_initial, %entry ], [ %add, %for.body ]47 %i.09 = phi i64 [ %sub, %for.body ], [ %N, %entry ]48 %arrayidx = getelementptr inbounds i32, ptr %A, i64 %i.0949 %load = load i32, ptr %arrayidx, align 450 %arrayidx1 = getelementptr inbounds i32, ptr %B, i64 %i.0951 %load_1 = load i32, ptr %arrayidx1, align 452; CHECK: %add = add i32 %load_1, %store_forwarded53 %add = add i32 %load_1, %load54 %sub = add i64 %i.09, -155 %arrayidx2 = getelementptr inbounds i32, ptr %A, i64 %sub56 store i32 %add, ptr %arrayidx2, align 457 %cmp.not = icmp eq i64 %sub, 058 br i1 %cmp.not, label %for.end, label %for.body59 60for.end: ; preds = %for.body61 ret void62}63 64