50 lines · plain
1; RUN: opt -passes='print<access-info>' %s -disable-output 2>&1 | FileCheck %s2 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.preheader28 29while.body.preheader: ; preds = %entry30 br label %while.body31 32while.body: ; preds = %while.body.preheader, %while.body33 %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 837 store i64 %0, ptr %op.addr.06, align 838 %add.ptr = getelementptr inbounds i8, ptr %src.addr.05, i64 839 %add.ptr1 = getelementptr inbounds i8, ptr %op.addr.06, i64 840 %sub = add nsw i32 %len.addr.07, -841 %cmp = icmp sgt i32 %len.addr.07, 842 br i1 %cmp, label %while.body, label %while.end.loopexit43 44while.end.loopexit: ; preds = %while.body45 br label %while.end46 47while.end: ; preds = %while.end.loopexit, %entry48 ret void49}50