xref: /llvm-project/llvm/test/Transforms/LoopLoadElim/pr46854-adress-spaces.ll (revision f0415f2a456d54daaa231c228d2c9f4ef2ce9b89)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; REQUIRES: amdgpu-registered-target
3
4; RUN: opt -passes='require<globals-aa>,loop-simplify,loop-load-elim' -S %s | FileCheck %s
5
6target datalayout = "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-ni:7:8"
7target triple = "amdgcn-amd-amdhsa"
8
9%struct.foo = type { %struct.pluto, i8, ptr, i32 }
10%struct.pluto = type { i32, i32, i32, ptr, i32, i32, i32 }
11%struct.wombat = type { %struct.barney }
12%struct.barney = type { <2 x float> }
13
14@global = external protected local_unnamed_addr addrspace(4) externally_initialized global %struct.foo, align 8
15@global.1 = internal unnamed_addr addrspace(3) constant [4000 x float] undef, align 16
16
17; Function Attrs: nounwind
18define protected amdgpu_kernel void @widget(i32 %arg, i32 %arg1) #0 {
19; CHECK-LABEL: @widget(
20; CHECK-NEXT:  bb:
21; CHECK-NEXT:    [[TMP:%.*]] = getelementptr inbounds [4000 x float], ptr addrspace(3) @global.1, i32 0, i32 [[ARG:%.*]]
22; CHECK-NEXT:    [[TMP2:%.*]] = load ptr, ptr addrspace(4) getelementptr inbounds (%struct.foo, ptr addrspace(4) @global, i64 0, i32 0, i32 3), align 8
23; CHECK-NEXT:    [[TMP3:%.*]] = getelementptr inbounds [[STRUCT_WOMBAT:%.*]], ptr [[TMP2]], i64 undef, i32 0
24; CHECK-NEXT:    br label [[BB5:%.*]]
25; CHECK:       bb5.loopexit:
26; CHECK-NEXT:    br label [[BB5]]
27; CHECK:       bb5:
28; CHECK-NEXT:    br label [[BB6:%.*]]
29; CHECK:       bb6:
30; CHECK-NEXT:    [[TMP7:%.*]] = phi i32 [ undef, [[BB5]] ], [ [[TMP19:%.*]], [[BB6]] ]
31; CHECK-NEXT:    [[TMP8:%.*]] = mul nsw i32 [[TMP7]], undef
32; CHECK-NEXT:    [[TMP9:%.*]] = add i32 [[TMP8]], undef
33; CHECK-NEXT:    [[TMP10:%.*]] = sext i32 [[TMP9]] to i64
34; CHECK-NEXT:    [[TMP11:%.*]] = getelementptr inbounds [[STRUCT_WOMBAT]], ptr [[TMP2]], i64 [[TMP10]]
35; CHECK-NEXT:    [[TMP13:%.*]] = load i64, ptr [[TMP11]], align 8
36; CHECK-NEXT:    [[TMP14:%.*]] = srem i32 1, [[ARG1:%.*]]
37; CHECK-NEXT:    [[TMP15:%.*]] = add nuw nsw i32 [[TMP14]], 1
38; CHECK-NEXT:    [[TMP16:%.*]] = getelementptr inbounds [4000 x float], ptr addrspace(3) @global.1, i32 0, i32 [[TMP15]]
39; CHECK-NEXT:    [[TMP17:%.*]] = load float, ptr addrspace(3) [[TMP16]], align 4
40; CHECK-NEXT:    [[TMP18:%.*]] = load float, ptr addrspace(3) [[TMP]], align 4
41; CHECK-NEXT:    store i64 [[TMP13]], ptr [[TMP3]], align 8
42; CHECK-NEXT:    [[TMP19]] = add nsw i32 [[TMP7]], 1
43; CHECK-NEXT:    [[TMP20:%.*]] = icmp slt i32 [[TMP7]], 3
44; CHECK-NEXT:    br i1 [[TMP20]], label [[BB6]], label [[BB5_LOOPEXIT:%.*]]
45;
46bb:
47  %tmp = getelementptr inbounds [4000 x float], ptr addrspace(3) @global.1, i32 0, i32 %arg
48  %tmp2 = load ptr, ptr addrspace(4) getelementptr inbounds (%struct.foo, ptr addrspace(4) @global, i64 0, i32 0, i32 3), align 8
49  %tmp3 = getelementptr inbounds %struct.wombat, ptr %tmp2, i64 undef, i32 0
50  br label %bb5
51
52bb5:                                              ; preds = %bb6, %bb
53  br label %bb6
54
55bb6:                                              ; preds = %bb6, %bb5
56  %tmp7 = phi i32 [ undef, %bb5 ], [ %tmp19, %bb6 ]
57  %tmp8 = mul nsw i32 %tmp7, undef
58  %tmp9 = add i32 %tmp8, undef
59  %tmp10 = sext i32 %tmp9 to i64
60  %tmp11 = getelementptr inbounds %struct.wombat, ptr %tmp2, i64 %tmp10
61  %tmp13 = load i64, ptr %tmp11, align 8
62  %tmp14 = srem i32 1, %arg1
63  %tmp15 = add nuw nsw i32 %tmp14, 1
64  %tmp16 = getelementptr inbounds [4000 x float], ptr addrspace(3) @global.1, i32 0, i32 %tmp15
65  %tmp17 = load float, ptr addrspace(3) %tmp16, align 4
66  %tmp18 = load float, ptr addrspace(3) %tmp, align 4
67  store i64 %tmp13, ptr %tmp3, align 8
68  %tmp19 = add nsw i32 %tmp7, 1
69  %tmp20 = icmp slt i32 %tmp7, 3
70  br i1 %tmp20, label %bb6, label %bb5
71}
72
73attributes #0 = { nounwind }
74