xref: /llvm-project/llvm/test/Transforms/LoopLoadElim/non-consecutive.ll (revision 055fb7795aa219a3d274d280ec9129784f169f56)
1971bc46fSRoman Lebedev; RUN: opt -passes=loop-load-elim -S < %s | FileCheck %s
2cee313d2SEric Christopher
3cee313d2SEric Christopher; The accesses to A are independent here but LAA reports it as a loop-carried
4cee313d2SEric Christopher; forward dependence.  Check that we don't perform st->ld forwarding between
5cee313d2SEric Christopher; them.
6cee313d2SEric Christopher;
7cee313d2SEric Christopher;   for (unsigned i = 0; i < 100; i++) {
8cee313d2SEric Christopher;     A[i][1] = B[i] + 2;
9cee313d2SEric Christopher;     C[i] = A[i][0] * 2;
10cee313d2SEric Christopher;   }
11cee313d2SEric Christopher
12cee313d2SEric Christophertarget datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
13cee313d2SEric Christopher
14*055fb779SNikita Popovdefine void @f(ptr noalias %A, ptr noalias %B, ptr noalias %C, i64 %N) {
15cee313d2SEric Christopher
16cee313d2SEric Christopherentry:
17cee313d2SEric Christopher  br label %for.body
18cee313d2SEric Christopher
19cee313d2SEric Christopherfor.body:                                         ; preds = %for.body, %entry
20cee313d2SEric Christopher  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
21cee313d2SEric Christopher  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
22cee313d2SEric Christopher
23*055fb779SNikita Popov  %A1idx = getelementptr inbounds [2 x i32], ptr %A, i64 %indvars.iv, i32 1
24*055fb779SNikita Popov  %Bidx = getelementptr inbounds i32, ptr %B, i64 %indvars.iv
25*055fb779SNikita Popov  %Cidx = getelementptr inbounds i32, ptr %C, i64 %indvars.iv
26*055fb779SNikita Popov  %A0idx = getelementptr inbounds [2 x i32], ptr %A, i64 %indvars.iv, i32 0
27cee313d2SEric Christopher
28*055fb779SNikita Popov  %b = load i32, ptr %Bidx, align 4
29cee313d2SEric Christopher  %a_p1 = add i32 %b, 2
30*055fb779SNikita Popov  store i32 %a_p1, ptr %A1idx, align 4
31cee313d2SEric Christopher
32*055fb779SNikita Popov; CHECK: %a = load i32, ptr %A0idx, align 4
33*055fb779SNikita Popov  %a = load i32, ptr %A0idx, align 4
34cee313d2SEric Christopher; CHECK: %c = mul i32 %a, 2
35cee313d2SEric Christopher  %c = mul i32 %a, 2
36*055fb779SNikita Popov  store i32 %c, ptr %Cidx, align 4
37cee313d2SEric Christopher
38cee313d2SEric Christopher  %exitcond = icmp eq i64 %indvars.iv.next, %N
39cee313d2SEric Christopher  br i1 %exitcond, label %for.end, label %for.body
40cee313d2SEric Christopher
41cee313d2SEric Christopherfor.end:                                          ; preds = %for.body
42cee313d2SEric Christopher  ret void
43cee313d2SEric Christopher}
44