xref: /llvm-project/llvm/test/Analysis/LoopAccessAnalysis/memcheck-off-by-one-error.ll (revision 05dc149c875cafcd948675dff4f7a7ccb092e128)
1; RUN: opt -passes='print<access-info>' %s -disable-output 2>&1 | FileCheck %s
2
3; This test verifies run-time boundary check of memory accesses.
4; The original loop:
5;   void fastCopy(const char* src, char* op) {
6;     int len = 32;
7;     while (len > 0) {
8;       *(reinterpret_cast<long long*>(op)) = *(reinterpret_cast<const long long*>(src));
9;       src += 8;
10;       op += 8;
11;       len -= 8;
12;     }
13;   }
14; Boundaries calculations before this patch:
15; (Low: %src High: (24 + %src))
16; and the actual distance between two pointers was 31,  (%op - %src = 31)
17; IsConflict = (24 > 31) = false -> execution is directed to the vectorized loop.
18; The loop was vectorized to 4, 32 byte memory access ( <4 x i64> ),
19; store a value at *%op touched memory under *%src.
20
21;CHECK: function 'fastCopy':
22;CHECK: (Low: %op High: (32 + %op))
23;CHECK: (Low: %src High: (32 + %src))
24
25define void @fastCopy(ptr nocapture readonly %src, ptr nocapture %op) {
26entry:
27  br label %while.body.preheader
28
29while.body.preheader:                             ; preds = %entry
30  br label %while.body
31
32while.body:                                       ; preds = %while.body.preheader, %while.body
33  %len.addr.07 = phi i32 [ %sub, %while.body ], [ 32, %while.body.preheader ]
34  %op.addr.06 = phi ptr [ %add.ptr1, %while.body ], [ %op, %while.body.preheader ]
35  %src.addr.05 = phi ptr [ %add.ptr, %while.body ], [ %src, %while.body.preheader ]
36  %0 = load i64, ptr %src.addr.05, align 8
37  store i64 %0, ptr %op.addr.06, align 8
38  %add.ptr = getelementptr inbounds i8, ptr %src.addr.05, i64 8
39  %add.ptr1 = getelementptr inbounds i8, ptr %op.addr.06, i64 8
40  %sub = add nsw i32 %len.addr.07, -8
41  %cmp = icmp sgt i32 %len.addr.07, 8
42  br i1 %cmp, label %while.body, label %while.end.loopexit
43
44while.end.loopexit:                               ; preds = %while.body
45  br label %while.end
46
47while.end:                                        ; preds = %while.end.loopexit, %entry
48  ret void
49}
50