1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes=infer-address-spaces %s | FileCheck %s
4 ; Test that pure GetElementPtr instructions not directly connected to
5 ; a memory operation are inferred.
7 @lds = internal unnamed_addr addrspace(3) global [648 x double] undef, align 8
9 define void @simplified_constexpr_gep_addrspacecast(i64 %idx0, i64 %idx1) {
10 ; CHECK-LABEL: @simplified_constexpr_gep_addrspacecast(
11 ; CHECK-NEXT: [[GEP0:%.*]] = getelementptr inbounds double, ptr addrspace(3) getelementptr inbounds ([648 x double], ptr addrspace(3) @lds, i64 0, i64 384), i64 [[IDX0:%.*]]
12 ; CHECK-NEXT: store double 1.000000e+00, ptr addrspace(3) [[GEP0]], align 8
13 ; CHECK-NEXT: ret void
15 %gep0 = getelementptr inbounds double, ptr addrspacecast (ptr addrspace(3) getelementptr inbounds ([648 x double], ptr addrspace(3) @lds, i64 0, i64 384) to ptr), i64 %idx0
16 %asc = addrspacecast ptr %gep0 to ptr addrspace(3)
17 store double 1.000000e+00, ptr addrspace(3) %asc, align 8
21 define void @constexpr_gep_addrspacecast(i64 %idx0, i64 %idx1) {
22 ; CHECK-LABEL: @constexpr_gep_addrspacecast(
23 ; CHECK-NEXT: [[GEP0:%.*]] = getelementptr inbounds double, ptr addrspace(3) getelementptr ([648 x double], ptr addrspace(3) @lds, i64 0, i64 384), i64 [[IDX0:%.*]]
24 ; CHECK-NEXT: store double 1.000000e+00, ptr addrspace(3) [[GEP0]], align 8
25 ; CHECK-NEXT: ret void
27 %gep0 = getelementptr inbounds double, ptr getelementptr ([648 x double], ptr addrspacecast (ptr addrspace(3) @lds to ptr), i64 0, i64 384), i64 %idx0
28 %asc = addrspacecast ptr %gep0 to ptr addrspace(3)
29 store double 1.0, ptr addrspace(3) %asc, align 8
33 define void @constexpr_gep_gep_addrspacecast(i64 %idx0, i64 %idx1) {
34 ; CHECK-LABEL: @constexpr_gep_gep_addrspacecast(
35 ; CHECK-NEXT: [[GEP0:%.*]] = getelementptr inbounds double, ptr addrspace(3) getelementptr ([648 x double], ptr addrspace(3) @lds, i64 0, i64 384), i64 [[IDX0:%.*]]
36 ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds double, ptr addrspace(3) [[GEP0]], i64 [[IDX1:%.*]]
37 ; CHECK-NEXT: store double 1.000000e+00, ptr addrspace(3) [[GEP1]], align 8
38 ; CHECK-NEXT: ret void
40 %gep0 = getelementptr inbounds double, ptr getelementptr ([648 x double], ptr addrspacecast (ptr addrspace(3) @lds to ptr), i64 0, i64 384), i64 %idx0
41 %gep1 = getelementptr inbounds double, ptr %gep0, i64 %idx1
42 %asc = addrspacecast ptr %gep1 to ptr addrspace(3)
43 store double 1.0, ptr addrspace(3) %asc, align 8
48 define amdgpu_kernel void @vector_gep(<4 x ptr addrspace(3)> %array) nounwind {
49 ; CHECK-LABEL: @vector_gep(
50 ; CHECK-NEXT: [[CAST:%.*]] = addrspacecast <4 x ptr addrspace(3)> [[ARRAY:%.*]] to <4 x ptr>
51 ; CHECK-NEXT: [[P:%.*]] = getelementptr [1024 x i32], <4 x ptr> [[CAST]], <4 x i16> zeroinitializer, <4 x i16> <i16 16, i16 16, i16 16, i16 16>
52 ; CHECK-NEXT: [[P0:%.*]] = extractelement <4 x ptr> [[P]], i32 0
53 ; CHECK-NEXT: [[P1:%.*]] = extractelement <4 x ptr> [[P]], i32 1
54 ; CHECK-NEXT: [[P2:%.*]] = extractelement <4 x ptr> [[P]], i32 2
55 ; CHECK-NEXT: [[P3:%.*]] = extractelement <4 x ptr> [[P]], i32 3
56 ; CHECK-NEXT: store i32 99, ptr [[P0]], align 4
57 ; CHECK-NEXT: store i32 99, ptr [[P1]], align 4
58 ; CHECK-NEXT: store i32 99, ptr [[P2]], align 4
59 ; CHECK-NEXT: store i32 99, ptr [[P3]], align 4
60 ; CHECK-NEXT: ret void
62 %cast = addrspacecast <4 x ptr addrspace(3)> %array to <4 x ptr>
63 %p = getelementptr [1024 x i32], <4 x ptr> %cast, <4 x i16> zeroinitializer, <4 x i16> <i16 16, i16 16, i16 16, i16 16>
64 %p0 = extractelement <4 x ptr> %p, i32 0
65 %p1 = extractelement <4 x ptr> %p, i32 1
66 %p2 = extractelement <4 x ptr> %p, i32 2
67 %p3 = extractelement <4 x ptr> %p, i32 3
75 define void @repeated_constexpr_gep_addrspacecast(i64 %idx0, i64 %idx1) {
76 ; CHECK-LABEL: @repeated_constexpr_gep_addrspacecast(
77 ; CHECK-NEXT: [[GEP0:%.*]] = getelementptr inbounds double, ptr addrspace(3) getelementptr ([648 x double], ptr addrspace(3) @lds, i64 0, i64 384), i64 [[IDX0:%.*]]
78 ; CHECK-NEXT: store double 1.000000e+00, ptr addrspace(3) [[GEP0]], align 8
79 ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds double, ptr addrspace(3) getelementptr ([648 x double], ptr addrspace(3) @lds, i64 0, i64 384), i64 [[IDX1:%.*]]
80 ; CHECK-NEXT: store double 1.000000e+00, ptr addrspace(3) [[GEP1]], align 8
81 ; CHECK-NEXT: ret void
83 %gep0 = getelementptr inbounds double, ptr getelementptr ([648 x double], ptr addrspacecast (ptr addrspace(3) @lds to ptr), i64 0, i64 384), i64 %idx0
84 %asc0 = addrspacecast ptr %gep0 to ptr addrspace(3)
85 store double 1.0, ptr addrspace(3) %asc0, align 8
87 %gep1 = getelementptr inbounds double, ptr getelementptr ([648 x double], ptr addrspacecast (ptr addrspace(3) @lds to ptr), i64 0, i64 384), i64 %idx1
88 %asc1 = addrspacecast ptr %gep1 to ptr addrspace(3)
89 store double 1.0, ptr addrspace(3) %asc1, align 8
94 define void @unorder_constexpr_gep_bitcast() {
95 ; CHECK-LABEL: @unorder_constexpr_gep_bitcast(
96 ; CHECK-NEXT: [[X0:%.*]] = load i32, ptr addrspace(3) @lds, align 4
97 ; CHECK-NEXT: [[X1:%.*]] = load i32, ptr addrspace(3) getelementptr (i32, ptr addrspace(3) @lds, i32 1), align 4
98 ; CHECK-NEXT: call void @use(i32 [[X0]], i32 [[X1]])
99 ; CHECK-NEXT: ret void
101 %x0 = load i32, ptr addrspacecast (ptr addrspace(3) @lds to ptr), align 4
102 %x1 = load i32, ptr getelementptr (i32, ptr addrspacecast (ptr addrspace(3) @lds to ptr), i32 1), align 4
103 call void @use(i32 %x0, i32 %x1)
107 declare void @use(i32, i32)