1# RUN: llc -march=amdgcn -mcpu=gfx803 -run-pass si-memory-legalizer  %s -o - | FileCheck %s
2
3--- |
4
5  define amdgpu_kernel void @multiple_mem_operands(i32 addrspace(1)* %out, i32 %cond, i32 %if_offset, i32 %else_offset) #0 {
6  entry:
7    %scratch0 = alloca [8192 x i32], addrspace(5)
8    %scratch1 = alloca [8192 x i32], addrspace(5)
9    %scratchptr01 = bitcast [8192 x i32] addrspace(5)* %scratch0 to i32 addrspace(5)*
10    store i32 1, i32 addrspace(5)* %scratchptr01
11    %scratchptr12 = bitcast [8192 x i32] addrspace(5)* %scratch1 to i32 addrspace(5)*
12    store i32 2, i32 addrspace(5)* %scratchptr12
13    %cmp = icmp eq i32 %cond, 0
14    br i1 %cmp, label %if, label %else, !structurizecfg.uniform !0, !amdgpu.uniform !0
15
16  if:                                               ; preds = %entry
17    %if_ptr = getelementptr [8192 x i32], [8192 x i32] addrspace(5)* %scratch0, i32 0, i32 %if_offset, !amdgpu.uniform !0
18    %if_value = load i32, i32 addrspace(5)* %if_ptr, align 4, !nontemporal !1
19    br label %done, !structurizecfg.uniform !0
20
21  else:                                             ; preds = %entry
22    %else_ptr = getelementptr [8192 x i32], [8192 x i32] addrspace(5)* %scratch1, i32 0, i32 %else_offset, !amdgpu.uniform !0
23    %else_value = load i32, i32 addrspace(5)* %else_ptr, align 4
24    br label %done, !structurizecfg.uniform !0
25
26  done:                                             ; preds = %else, %if
27    %value = phi i32 [ %if_value, %if ], [ %else_value, %else ]
28    store i32 %value, i32 addrspace(1)* %out
29    ret void
30  }
31
32  attributes #0 = { "target-cpu"="gfx803" }
33  attributes #1 = { convergent nounwind }
34  attributes #2 = { convergent nounwind readnone }
35
36  !0 = !{}
37  !1 = !{i32 1}
38
39...
40---
41
42# CHECK-LABEL: name: multiple_mem_operands
43
44# CHECK-LABEL: bb.3.done:
45# CHECK: BUFFER_LOAD_DWORD_OFFEN killed $vgpr0, killed $sgpr8_sgpr9_sgpr10_sgpr11, $sgpr3, 0, 0, 0, 0, 0
46
47name:            multiple_mem_operands
48alignment:       1
49exposesReturnsTwice: false
50legalized:       false
51regBankSelected: false
52selected:        false
53tracksRegLiveness: true
54registers:
55liveins:
56  - { reg: '$sgpr0_sgpr1', virtual-reg: '' }
57  - { reg: '$sgpr3', virtual-reg: '' }
58frameInfo:
59  isFrameAddressTaken: false
60  isReturnAddressTaken: false
61  hasStackMap:     false
62  hasPatchPoint:   false
63  stackSize:       65540
64  offsetAdjustment: 0
65  maxAlignment:    4
66  adjustsStack:    false
67  hasCalls:        false
68  stackProtector:  ''
69  maxCallFrameSize: 0
70  hasOpaqueSPAdjustment: false
71  hasVAStart:      false
72  hasMustTailInVarArgFunc: false
73  savePoint:       ''
74  restorePoint:    ''
75fixedStack:
76  - { id: 0, type: default, offset: 0, size: 4, alignment: 4, stack-id: default,
77      isImmutable: false, isAliased: false, callee-saved-register: '' }
78stack:
79  - { id: 0, name: scratch0, type: default, offset: 4, size: 32768, alignment: 4,
80      stack-id: default, callee-saved-register: '', local-offset: 0,
81      debug-info-variable: '', debug-info-expression: '',
82      debug-info-location: '' }
83  - { id: 1, name: scratch1, type: default, offset: 32772, size: 32768,
84      alignment: 4, stack-id: default, callee-saved-register: '', local-offset: 32768,
85      debug-info-variable: '', debug-info-expression: '',
86      debug-info-location: '' }
87constants:
88body:             |
89  bb.0.entry:
90    successors: %bb.1.if(0x30000000), %bb.2.else(0x50000000)
91    liveins: $sgpr0_sgpr1, $sgpr3
92
93    $sgpr2 = S_LOAD_DWORD_IMM $sgpr0_sgpr1, 44, 0, 0 :: (non-temporal dereferenceable invariant load 4 from `i32 addrspace(4)* undef`)
94    $sgpr8 = S_MOV_B32 &SCRATCH_RSRC_DWORD0, implicit-def $sgpr8_sgpr9_sgpr10_sgpr11
95    $sgpr4_sgpr5 = S_LOAD_DWORDX2_IMM $sgpr0_sgpr1, 36, 0, 0 :: (non-temporal dereferenceable invariant load 8 from `i64 addrspace(4)* undef`)
96    $sgpr9 = S_MOV_B32 &SCRATCH_RSRC_DWORD1, implicit-def $sgpr8_sgpr9_sgpr10_sgpr11
97    $sgpr10 = S_MOV_B32 4294967295, implicit-def $sgpr8_sgpr9_sgpr10_sgpr11
98    $sgpr11 = S_MOV_B32 15204352, implicit-def $sgpr8_sgpr9_sgpr10_sgpr11
99    $vgpr0 = V_MOV_B32_e32 1, implicit $exec
100    BUFFER_STORE_DWORD_OFFSET killed $vgpr0, $sgpr8_sgpr9_sgpr10_sgpr11, $sgpr3, 4, 0, 0, 0, 0, 0, implicit $exec :: (store 4 into %ir.scratchptr01)
101    S_WAITCNT 127
102    S_CMP_LG_U32 killed $sgpr2, 0, implicit-def $scc
103    S_WAITCNT 3855
104    $vgpr0 = V_MOV_B32_e32 2, implicit $exec
105    $vgpr1 = V_MOV_B32_e32 32772, implicit $exec
106    BUFFER_STORE_DWORD_OFFEN killed $vgpr0, killed $vgpr1, $sgpr8_sgpr9_sgpr10_sgpr11, $sgpr3, 0, 0, 0, 0, 0, 0, implicit $exec :: (store 4 into %ir.scratchptr12)
107    S_CBRANCH_SCC0 %bb.1.if, implicit killed $scc
108
109  bb.2.else:
110    successors: %bb.3.done(0x80000000)
111    liveins: $sgpr0_sgpr1, $sgpr4_sgpr5, $sgpr3, $sgpr8_sgpr9_sgpr10_sgpr11
112
113    $sgpr0 = S_LOAD_DWORD_IMM killed $sgpr0_sgpr1, 52, 0, 0 :: (non-temporal dereferenceable invariant load 4 from `i32 addrspace(4)* undef`)
114    S_WAITCNT 3855
115    $vgpr0 = V_MOV_B32_e32 32772, implicit $exec
116    S_BRANCH %bb.3.done
117
118  bb.1.if:
119    successors: %bb.3.done(0x80000000)
120    liveins: $sgpr0_sgpr1, $sgpr4_sgpr5, $sgpr3, $sgpr8_sgpr9_sgpr10_sgpr11
121
122    $sgpr0 = S_LOAD_DWORD_IMM killed $sgpr0_sgpr1, 48, 0, 0 :: (non-temporal dereferenceable invariant load 4 from `i32 addrspace(4)* undef`)
123    S_WAITCNT 3855
124    $vgpr0 = V_MOV_B32_e32 4, implicit $exec
125
126  bb.3.done:
127    liveins: $sgpr3, $sgpr4_sgpr5, $sgpr8_sgpr9_sgpr10_sgpr11, $vgpr0, $sgpr0
128
129    S_WAITCNT 127
130    $sgpr0 = S_LSHL_B32 killed $sgpr0, 2, implicit-def dead $scc
131    $vgpr0 = V_ADD_CO_U32_e32 killed $sgpr0, killed $vgpr0, implicit-def dead $vcc, implicit $exec
132    $vgpr0 = BUFFER_LOAD_DWORD_OFFEN killed $vgpr0, killed $sgpr8_sgpr9_sgpr10_sgpr11, $sgpr3, 0, 0, 0, 0, 0, 0, implicit $exec :: (load 4 from %ir.else_ptr), (non-temporal load 4 from %ir.if_ptr)
133    $vgpr1 = V_MOV_B32_e32 $sgpr4, implicit $exec, implicit-def $vgpr1_vgpr2, implicit $sgpr4_sgpr5
134    $vgpr2 = V_MOV_B32_e32 killed $sgpr5, implicit $exec, implicit $sgpr4_sgpr5, implicit $exec
135    S_WAITCNT 3952
136    FLAT_STORE_DWORD killed $vgpr1_vgpr2, killed $vgpr0, 0, 0, 0, 0, implicit $exec, implicit $flat_scr :: (store 4 into %ir.out)
137    S_ENDPGM 0
138
139...
140