xref: /llvm-project/llvm/test/Analysis/LoopAccessAnalysis/memcheck-store-vs-alloc-size.ll (revision 05dc149c875cafcd948675dff4f7a7ccb092e128)
1; RUN: opt -passes='print<access-info>' %s -disable-output 2>&1 | FileCheck %s
2
3; This test defends against accidentally using alloc size instead of store size when performing run-time
4; boundary check of memory accesses. The IR in this file is based on
5; llvm/test/Analysis/LoopAccessAnalysis/memcheck-off-by-one-error.ll.
6; Here, we use i19 instead of i64 because it has a different alloc size to its store size.
7
8;CHECK: function 'fastCopy':
9;CHECK: (Low: %op High: (27 + %op))
10;CHECK: (Low: %src High: (27 + %src))
11
12define void @fastCopy(ptr nocapture readonly %src, ptr nocapture %op) {
13entry:
14  br label %while.body.preheader
15
16while.body.preheader:                             ; preds = %entry
17  br label %while.body
18
19while.body:                                       ; preds = %while.body.preheader, %while.body
20  %len.addr.07 = phi i32 [ %sub, %while.body ], [ 32, %while.body.preheader ]
21  %op.addr.06 = phi ptr [ %add.ptr1, %while.body ], [ %op, %while.body.preheader ]
22  %src.addr.05 = phi ptr [ %add.ptr, %while.body ], [ %src, %while.body.preheader ]
23  %0 = load i19, ptr %src.addr.05, align 8
24  store i19 %0, ptr %op.addr.06, align 8
25  %add.ptr = getelementptr inbounds i8, ptr %src.addr.05, i19 8
26  %add.ptr1 = getelementptr inbounds i8, ptr %op.addr.06, i19 8
27  %sub = add nsw i32 %len.addr.07, -8
28  %cmp = icmp sgt i32 %len.addr.07, 8
29  br i1 %cmp, label %while.body, label %while.end.loopexit
30
31while.end.loopexit:                               ; preds = %while.body
32  br label %while.end
33
34while.end:                                        ; preds = %while.end.loopexit, %entry
35  ret void
36}
37