1 ; Test optional annotation of stack addresses.
3 ; RUN: opt < %s -passes='function(memprof),module(memprof-module)' -S | FileCheck --check-prefixes=CHECK %s
4 ; RUN: opt < %s -passes='function(memprof),module(memprof-module)' -memprof-instrument-stack -S | FileCheck --check-prefixes=CHECK,STACK %s
6 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
7 target triple = "x86_64-unknown-linux-gnu"
9 define i32 @test_stack_load() {
11 %x = alloca i32, align 4
12 %tmp1 = load i32, ptr %x, align 4
15 ; CHECK-LABEL: @test_stack_load
16 ; CHECK: %[[SHADOW_OFFSET:[^ ]*]] = load i64, ptr @__memprof_shadow_memory_dynamic_address
17 ; CHECK-NEXT: %x = alloca i32
18 ; STACK-NEXT: %[[LOAD_ADDR:[^ ]*]] = ptrtoint ptr %x to i64
19 ; STACK-NEXT: %[[MASKED_ADDR:[^ ]*]] = and i64 %[[LOAD_ADDR]], -64
20 ; STACK-NEXT: %[[SHIFTED_ADDR:[^ ]*]] = lshr i64 %[[MASKED_ADDR]], 3
21 ; STACK-NEXT: add i64 %[[SHIFTED_ADDR]], %[[SHADOW_OFFSET]]
22 ; STACK-NEXT: %[[LOAD_SHADOW_PTR:[^ ]*]] = inttoptr
23 ; STACK-NEXT: %[[LOAD_SHADOW:[^ ]*]] = load i64, ptr %[[LOAD_SHADOW_PTR]]
24 ; STACK-NEXT: %[[NEW_SHADOW:[^ ]*]] = add i64 %[[LOAD_SHADOW]], 1
25 ; STACK-NEXT: store i64 %[[NEW_SHADOW]], ptr %[[LOAD_SHADOW_PTR]]
27 ; CHECK-NEXT: %tmp1 = load i32, ptr %x
28 ; CHECK-NEXT: ret i32 %tmp1
30 define void @test_stack_store() {
32 %x = alloca i32, align 4
33 store i32 1, ptr %x, align 4
36 ; CHECK-LABEL: @test_stack_store
37 ; CHECK: %[[SHADOW_OFFSET:[^ ]*]] = load i64, ptr @__memprof_shadow_memory_dynamic_address
38 ; CHECK-NEXT: %x = alloca i32
39 ; STACK-NEXT: %[[STORE_ADDR:[^ ]*]] = ptrtoint ptr %x to i64
40 ; STACK-NEXT: %[[MASKED_ADDR:[^ ]*]] = and i64 %[[STORE_ADDR]], -64
41 ; STACK-NEXT: %[[SHIFTED_ADDR:[^ ]*]] = lshr i64 %[[MASKED_ADDR]], 3
42 ; STACK-NEXT: add i64 %[[SHIFTED_ADDR]], %[[SHADOW_OFFSET]]
43 ; STACK-NEXT: %[[STORE_SHADOW_PTR:[^ ]*]] = inttoptr
44 ; STACK-NEXT: %[[STORE_SHADOW:[^ ]*]] = load i64, ptr %[[STORE_SHADOW_PTR]]
45 ; STACK-NEXT: %[[NEW_SHADOW:[^ ]*]] = add i64 %[[STORE_SHADOW]], 1
46 ; STACK-NEXT: store i64 %[[NEW_SHADOW]], ptr %[[STORE_SHADOW_PTR]]
48 ; CHECK-NEXT: store i32 1, ptr %x
49 ; CHECK-NEXT: ret void