xref: /llvm-project/llvm/test/Transforms/LoopLoadElim/memcheck.ll (revision 055fb7795aa219a3d274d280ec9129784f169f56)
1971bc46fSRoman Lebedev; RUN: opt -passes=loop-load-elim -S < %s | FileCheck %s
2971bc46fSRoman Lebedev; RUN: opt -passes=loop-load-elim -S -runtime-check-per-loop-load-elim=2 < %s | FileCheck %s --check-prefix=AGGRESSIVE
3cee313d2SEric Christopher
4cee313d2SEric Christopher; This needs two pairs of memchecks (A * { C, D }) for a single load
5cee313d2SEric Christopher; elimination which is considered to expansive by default.
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] * 2;
10cee313d2SEric Christopher;     D[i] = 2;
11cee313d2SEric Christopher;   }
12cee313d2SEric Christopher
13cee313d2SEric Christophertarget datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
14cee313d2SEric Christopher
15*055fb779SNikita Popovdefine void @f(ptr  %A, ptr  %B, ptr  %C, i64 %N, ptr %D) {
16cee313d2SEric Christopherentry:
17cee313d2SEric Christopher  br label %for.body
18cee313d2SEric Christopher
19cee313d2SEric Christopher; AGGRESSIVE: for.body.lver.check:
20cee313d2SEric Christopher; AGGRESSIVE: %found.conflict{{.*}} =
21cee313d2SEric Christopher; AGGRESSIVE: %found.conflict{{.*}} =
22cee313d2SEric Christopher; AGGRESSIVE-NOT: %found.conflict{{.*}} =
23cee313d2SEric Christopher
24cee313d2SEric Christopherfor.body:                                         ; preds = %for.body, %entry
25cee313d2SEric Christopher; CHECK-NOT: %store_forwarded =
26cee313d2SEric Christopher; AGGRESSIVE: %store_forwarded =
27cee313d2SEric Christopher  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
28cee313d2SEric Christopher  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
29cee313d2SEric Christopher
30*055fb779SNikita Popov  %Aidx_next = getelementptr inbounds i32, ptr %A, i64 %indvars.iv.next
31*055fb779SNikita Popov  %Bidx = getelementptr inbounds i32, ptr %B, i64 %indvars.iv
32*055fb779SNikita Popov  %Cidx = getelementptr inbounds i32, ptr %C, i64 %indvars.iv
33*055fb779SNikita Popov  %Aidx = getelementptr inbounds i32, ptr %A, i64 %indvars.iv
34*055fb779SNikita Popov  %Didx = getelementptr inbounds i32, ptr %D, i64 %indvars.iv
35cee313d2SEric Christopher
36*055fb779SNikita Popov  %b = load i32, ptr %Bidx, align 4
37cee313d2SEric Christopher  %a_p1 = add i32 %b, 2
38*055fb779SNikita Popov  store i32 %a_p1, ptr %Aidx_next, align 4
39cee313d2SEric Christopher
40*055fb779SNikita Popov  %a = load i32, ptr %Aidx, align 4
41cee313d2SEric Christopher; CHECK: %c = mul i32 %a, 2
42cee313d2SEric Christopher; AGGRESSIVE: %c = mul i32 %store_forwarded, 2
43cee313d2SEric Christopher  %c = mul i32 %a, 2
44*055fb779SNikita Popov  store i32 %c, ptr %Cidx, align 4
45*055fb779SNikita Popov  store i32 2, ptr %Didx, align 4
46cee313d2SEric Christopher
47cee313d2SEric Christopher  %exitcond = icmp eq i64 %indvars.iv.next, %N
48cee313d2SEric Christopher  br i1 %exitcond, label %for.end, label %for.body
49cee313d2SEric Christopher
50cee313d2SEric Christopherfor.end:                                          ; preds = %for.body
51cee313d2SEric Christopher  ret void
52cee313d2SEric Christopher}
53