1; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -infer-address-spaces %s | FileCheck %s 2 3; Test that pure addrspacecast instructions not directly connected to 4; a memory operation are inferred. 5 6; CHECK-LABEL: @addrspacecast_gep_addrspacecast( 7; CHECK: %gep0 = getelementptr i32, i32 addrspace(3)* %ptr, i64 9 8; CHECK-NEXT: store i32 8, i32 addrspace(3)* %gep0, align 8 9; CHECK-NEXT: ret void 10define void @addrspacecast_gep_addrspacecast(i32 addrspace(3)* %ptr) { 11 %asc0 = addrspacecast i32 addrspace(3)* %ptr to i32* 12 %gep0 = getelementptr i32, i32* %asc0, i64 9 13 %asc1 = addrspacecast i32* %gep0 to i32 addrspace(3)* 14 store i32 8, i32 addrspace(3)* %asc1, align 8 15 ret void 16} 17 18; CHECK-LABEL: @addrspacecast_different_pointee_type( 19; CHECK: [[GEP:%.*]] = getelementptr i32, i32 addrspace(3)* %ptr, i64 9 20; CHECK: [[CAST:%.*]] = bitcast i32 addrspace(3)* [[GEP]] to i8 addrspace(3)* 21; CHECK-NEXT: store i8 8, i8 addrspace(3)* [[CAST]], align 8 22; CHECK-NEXT: ret void 23define void @addrspacecast_different_pointee_type(i32 addrspace(3)* %ptr) { 24 %asc0 = addrspacecast i32 addrspace(3)* %ptr to i32* 25 %gep0 = getelementptr i32, i32* %asc0, i64 9 26 %asc1 = addrspacecast i32* %gep0 to i8 addrspace(3)* 27 store i8 8, i8 addrspace(3)* %asc1, align 8 28 ret void 29} 30 31; CHECK-LABEL: @addrspacecast_to_memory( 32; CHECK: %gep0 = getelementptr i32, i32 addrspace(3)* %ptr, i64 9 33; CHECK-NEXT: store volatile i32 addrspace(3)* %gep0, i32 addrspace(3)* addrspace(1)* undef 34; CHECK-NEXT: ret void 35define void @addrspacecast_to_memory(i32 addrspace(3)* %ptr) { 36 %asc0 = addrspacecast i32 addrspace(3)* %ptr to i32* 37 %gep0 = getelementptr i32, i32* %asc0, i64 9 38 %asc1 = addrspacecast i32* %gep0 to i32 addrspace(3)* 39 store volatile i32 addrspace(3)* %asc1, i32 addrspace(3)* addrspace(1)* undef 40 ret void 41} 42 43; CHECK-LABEL: @multiuse_addrspacecast_gep_addrspacecast( 44; CHECK: %asc0 = addrspacecast i32 addrspace(3)* %ptr to i32* 45; CHECK-NEXT: store volatile i32* %asc0, i32* addrspace(1)* undef 46; CHECK-NEXT: %gep0 = getelementptr i32, i32 addrspace(3)* %ptr, i64 9 47; CHECK-NEXT: store i32 8, i32 addrspace(3)* %gep0, align 8 48; CHECK-NEXT: ret void 49define void @multiuse_addrspacecast_gep_addrspacecast(i32 addrspace(3)* %ptr) { 50 %asc0 = addrspacecast i32 addrspace(3)* %ptr to i32* 51 store volatile i32* %asc0, i32* addrspace(1)* undef 52 %gep0 = getelementptr i32, i32* %asc0, i64 9 53 %asc1 = addrspacecast i32* %gep0 to i32 addrspace(3)* 54 store i32 8, i32 addrspace(3)* %asc1, align 8 55 ret void 56} 57