1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2 ; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes=infer-address-spaces %s | FileCheck %s
4 ; Make sure memory instructions where the pointer appears in both a
5 ; pointer and value operand work correctly.
7 declare void @user(ptr)
9 ; Make sure only the pointer operand use of the store is replaced
10 define void @store_flat_pointer_to_self() {
11 ; CHECK-LABEL: define void @store_flat_pointer_to_self() {
12 ; CHECK-NEXT: [[ALLOCA:%.*]] = alloca ptr, align 8, addrspace(5)
13 ; CHECK-NEXT: [[FLAT:%.*]] = addrspacecast ptr addrspace(5) [[ALLOCA]] to ptr
14 ; CHECK-NEXT: store ptr [[FLAT]], ptr addrspace(5) [[ALLOCA]], align 8
15 ; CHECK-NEXT: call void @user(ptr [[FLAT]])
16 ; CHECK-NEXT: ret void
18 %alloca = alloca ptr, align 8, addrspace(5)
19 %flat = addrspacecast ptr addrspace(5) %alloca to ptr
20 store ptr %flat, ptr %flat, align 8
21 call void @user(ptr %flat)
25 ; FIXME: Should be able to optimize the pointer operand to flat.
26 define ptr @atomicrmw_xchg_flat_pointer_to_self() {
27 ; CHECK-LABEL: define ptr @atomicrmw_xchg_flat_pointer_to_self() {
28 ; CHECK-NEXT: [[ALLOCA:%.*]] = alloca ptr, align 8, addrspace(5)
29 ; CHECK-NEXT: [[FLAT:%.*]] = addrspacecast ptr addrspace(5) [[ALLOCA]] to ptr
30 ; CHECK-NEXT: [[XCHG:%.*]] = atomicrmw xchg ptr [[FLAT]], ptr [[FLAT]] seq_cst, align 8
31 ; CHECK-NEXT: call void @user(ptr [[FLAT]])
32 ; CHECK-NEXT: ret ptr [[XCHG]]
34 %alloca = alloca ptr, align 8, addrspace(5)
35 %flat = addrspacecast ptr addrspace(5) %alloca to ptr
36 %xchg = atomicrmw xchg ptr %flat, ptr %flat seq_cst, align 8
37 call void @user(ptr %flat)
41 define { ptr, i1 } @cmpxchg_flat_pointer_new_to_self(ptr %cmp) {
42 ; CHECK-LABEL: define { ptr, i1 } @cmpxchg_flat_pointer_new_to_self(
43 ; CHECK-SAME: ptr [[CMP:%.*]]) {
44 ; CHECK-NEXT: [[ALLOCA:%.*]] = alloca ptr, align 8, addrspace(5)
45 ; CHECK-NEXT: [[FLAT:%.*]] = addrspacecast ptr addrspace(5) [[ALLOCA]] to ptr
46 ; CHECK-NEXT: [[CMPX:%.*]] = cmpxchg ptr [[FLAT]], ptr [[CMP]], ptr [[FLAT]] seq_cst seq_cst, align 8
47 ; CHECK-NEXT: call void @user(ptr [[FLAT]])
48 ; CHECK-NEXT: ret { ptr, i1 } [[CMPX]]
50 %alloca = alloca ptr, align 8, addrspace(5)
51 %flat = addrspacecast ptr addrspace(5) %alloca to ptr
52 %cmpx = cmpxchg ptr %flat, ptr %cmp, ptr %flat seq_cst seq_cst, align 8
53 call void @user(ptr %flat)
57 define { ptr, i1 } @cmpxchg_flat_pointer_cmp_to_self(ptr %new) {
58 ; CHECK-LABEL: define { ptr, i1 } @cmpxchg_flat_pointer_cmp_to_self(
59 ; CHECK-SAME: ptr [[NEW:%.*]]) {
60 ; CHECK-NEXT: [[ALLOCA:%.*]] = alloca ptr, align 8, addrspace(5)
61 ; CHECK-NEXT: [[FLAT:%.*]] = addrspacecast ptr addrspace(5) [[ALLOCA]] to ptr
62 ; CHECK-NEXT: [[CMPX:%.*]] = cmpxchg ptr [[FLAT]], ptr [[FLAT]], ptr [[NEW]] seq_cst seq_cst, align 8
63 ; CHECK-NEXT: call void @user(ptr [[FLAT]])
64 ; CHECK-NEXT: ret { ptr, i1 } [[CMPX]]
66 %alloca = alloca ptr, align 8, addrspace(5)
67 %flat = addrspacecast ptr addrspace(5) %alloca to ptr
68 %cmpx = cmpxchg ptr %flat, ptr %flat, ptr %new seq_cst seq_cst, align 8
69 call void @user(ptr %flat)