about summary refs log tree commit diff
path: root/tests/mir-opt/gvn_repeat.rs
blob: bbbb2a7ccbaf5d93341a07a2cd87b6ddf2ea8539 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//@ test-mir-pass: GVN

#![feature(custom_mir, core_intrinsics)]

// Check that we do not introduce out-of-bounds access.

use std::intrinsics::mir::*;

// EMIT_MIR gvn_repeat.repeat_place.GVN.diff
#[custom_mir(dialect = "runtime")]
pub fn repeat_place(mut idx1: usize, idx2: usize, val: &i32) -> i32 {
    // CHECK-LABEL: fn repeat_place(
    // CHECK: let mut [[ELEM:.*]]: &i32;
    // CHECK: _0 = copy (*[[ELEM]])
    mir! {
        let array;
        let elem;
        {
            array = [*val; 5];
            elem = &array[idx1];
            idx1 = idx2;
            RET = *elem;
            Return()
        }
    }
}

// EMIT_MIR gvn_repeat.repeat_local.GVN.diff
#[custom_mir(dialect = "runtime")]
pub fn repeat_local(mut idx1: usize, idx2: usize, val: i32) -> i32 {
    // CHECK-LABEL: fn repeat_local(
    // CHECK: _0 = copy _3
    mir! {
        let array;
        let elem;
        {
            array = [val; 5];
            elem = &array[idx1];
            idx1 = idx2;
            RET = *elem;
            Return()
        }
    }
}

fn main() {
    assert_eq!(repeat_place(0, 5, &0), 0);
    assert_eq!(repeat_local(0, 5, 0), 0);
}