From f83901bb89e4043268ec3bf033b435d56e1ed303 Mon Sep 17 00:00:00 2001 From: Falco Hirschenberger Date: Fri, 21 Apr 2017 09:00:34 +0200 Subject: Adding support for the llvm `prefetch` intrinsic Related to #37251 --- src/test/codegen/prefetch.rs | 75 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/test/codegen/prefetch.rs (limited to 'src/test/codegen') diff --git a/src/test/codegen/prefetch.rs b/src/test/codegen/prefetch.rs new file mode 100644 index 00000000000..9ca2f01f80d --- /dev/null +++ b/src/test/codegen/prefetch.rs @@ -0,0 +1,75 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags: -C no-prepopulate-passes + +#![crate_type = "lib"] +#![feature(core_intrinsics)] + +use std::intrinsics::{prefetch_read_data, prefetch_write_data, + prefetch_read_instruction, prefetch_write_instruction}; + +#[no_mangle] +pub fn check_prefetch_read_data(data: &[i8]) { + unsafe { + // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 0, i32 1) + prefetch_read_data(data.as_ptr(), 0); + // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 1, i32 1) + prefetch_read_data(data.as_ptr(), 1); + // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 2, i32 1) + prefetch_read_data(data.as_ptr(), 2); + // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 3, i32 1) + prefetch_read_data(data.as_ptr(), 3); + } +} + +#[no_mangle] +pub fn check_prefetch_write_data(data: &[i8]) { + unsafe { + // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 0, i32 1) + prefetch_write_data(data.as_ptr(), 0); + // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 1, i32 1) + prefetch_write_data(data.as_ptr(), 1); + // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 2, i32 1) + prefetch_write_data(data.as_ptr(), 2); + // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 3, i32 1) + prefetch_write_data(data.as_ptr(), 3); + } +} + +#[no_mangle] +pub fn check_prefetch_read_instruction(data: &[i8]) { + unsafe { + // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 0, i32 0) + prefetch_read_instruction(data.as_ptr(), 0); + // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 1, i32 0) + prefetch_read_instruction(data.as_ptr(), 1); + // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 2, i32 0) + prefetch_read_instruction(data.as_ptr(), 2); + // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 0, i32 3, i32 0) + prefetch_read_instruction(data.as_ptr(), 3); + } +} + +#[no_mangle] +pub fn check_prefetch_write_instruction(data: &[i8]) { + unsafe { + // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 0, i32 0) + prefetch_write_instruction(data.as_ptr(), 0); + // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 1, i32 0) + prefetch_write_instruction(data.as_ptr(), 1); + // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 2, i32 0) + prefetch_write_instruction(data.as_ptr(), 2); + // CHECK: call void @llvm.prefetch(i8* %{{.*}}, i32 1, i32 3, i32 0) + prefetch_write_instruction(data.as_ptr(), 3); + } +} + + -- cgit 1.4.1-3-g733a5