xref: /llvm-project/llvm/test/Transforms/LoopLoadElim/forward.ll (revision 055fb7795aa219a3d274d280ec9129784f169f56)
1971bc46fSRoman Lebedev; RUN: opt -passes=loop-load-elim -S < %s | FileCheck %s
2cee313d2SEric Christopher
3cee313d2SEric Christopher; Simple st->ld forwarding derived from a lexical forward dep.
4cee313d2SEric Christopher;
5cee313d2SEric Christopher;   for (unsigned i = 0; i < 100; i++) {
6cee313d2SEric Christopher;     A[i+1] = B[i] + 2;
7cee313d2SEric Christopher;     C[i] = A[i] * 2;
8cee313d2SEric Christopher;   }
9cee313d2SEric Christopher
10cee313d2SEric Christophertarget datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
11cee313d2SEric Christopher
12*055fb779SNikita Popovdefine void @f(ptr %A, ptr %B, ptr %C, i64 %N) {
13cee313d2SEric Christopher
14cee313d2SEric Christopher; CHECK:   for.body.lver.check:
15cee313d2SEric Christopher; CHECK:     %found.conflict{{.*}} =
16cee313d2SEric Christopher; CHECK-NOT: %found.conflict{{.*}} =
17cee313d2SEric Christopher
18cee313d2SEric Christopherentry:
19cee313d2SEric Christopher; Make sure the hoisted load keeps the alignment
20*055fb779SNikita Popov; CHECK: %load_initial = load i32, ptr %A, align 1
21cee313d2SEric Christopher  br label %for.body
22cee313d2SEric Christopher
23cee313d2SEric Christopherfor.body:                                         ; preds = %for.body, %entry
24cee313d2SEric Christopher; CHECK: %store_forwarded = phi i32 [ %load_initial, %for.body.ph ], [ %a_p1, %for.body ]
25cee313d2SEric Christopher  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
26cee313d2SEric Christopher  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
27cee313d2SEric Christopher
28*055fb779SNikita Popov  %Aidx_next = getelementptr inbounds i32, ptr %A, i64 %indvars.iv.next
29*055fb779SNikita Popov  %Bidx = getelementptr inbounds i32, ptr %B, i64 %indvars.iv
30*055fb779SNikita Popov  %Cidx = getelementptr inbounds i32, ptr %C, i64 %indvars.iv
31*055fb779SNikita Popov  %Aidx = getelementptr inbounds i32, ptr %A, i64 %indvars.iv
32cee313d2SEric Christopher
33*055fb779SNikita Popov  %b = load i32, ptr %Bidx, align 4
34cee313d2SEric Christopher  %a_p1 = add i32 %b, 2
35*055fb779SNikita Popov  store i32 %a_p1, ptr %Aidx_next, align 4
36cee313d2SEric Christopher
37*055fb779SNikita Popov  %a = load i32, ptr %Aidx, align 1
38cee313d2SEric Christopher; CHECK: %c = mul i32 %store_forwarded, 2
39cee313d2SEric Christopher  %c = mul i32 %a, 2
40*055fb779SNikita Popov  store i32 %c, ptr %Cidx, align 4
41cee313d2SEric Christopher
42cee313d2SEric Christopher  %exitcond = icmp eq i64 %indvars.iv.next, %N
43cee313d2SEric Christopher  br i1 %exitcond, label %for.end, label %for.body
44cee313d2SEric Christopher
45cee313d2SEric Christopherfor.end:                                          ; preds = %for.body
46cee313d2SEric Christopher  ret void
47cee313d2SEric Christopher}
48