llvm.org GIT mirror llvm / 074105b
Merging r243462: ------------------------------------------------------------------------ r243462 | Matthew.Arsenault | 2015-07-28 14:47:00 -0400 (Tue, 28 Jul 2015) | 5 lines AMDGPU: Don't try to use LDS/vector for private if pointer value stored If the pointer is the store's value operand, this would produce a broken module. Make sure the use is actually for the pointer operand. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_37@253228 91177308-0d34-0410-b5e6-96231b3b80d8 Tom Stellard 3 years ago
2 changed file(s) with 66 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
133133 //
134134 // TODO: Check isTriviallyVectorizable for calls and handle other
135135 // instructions.
136 static bool canVectorizeInst(Instruction *Inst) {
136 static bool canVectorizeInst(Instruction *Inst, User *User) {
137137 switch (Inst->getOpcode()) {
138138 case Instruction::Load:
139 case Instruction::Store:
140139 case Instruction::BitCast:
141140 case Instruction::AddrSpaceCast:
142141 return true;
142 case Instruction::Store: {
143 // Must be the stored pointer operand, not a stored value.
144 StoreInst *SI = cast(Inst);
145 return SI->getPointerOperand() == User;
146 }
143147 default:
144148 return false;
145149 }
165169 for (User *AllocaUser : Alloca->users()) {
166170 GetElementPtrInst *GEP = dyn_cast(AllocaUser);
167171 if (!GEP) {
168 if (!canVectorizeInst(cast(AllocaUser)))
172 if (!canVectorizeInst(cast(AllocaUser), Alloca))
169173 return false;
170174
171175 WorkList.push_back(AllocaUser);
183187
184188 GEPVectorIdx[GEP] = Index;
185189 for (User *GEPUser : AllocaUser->users()) {
186 if (!canVectorizeInst(cast(GEPUser)))
190 if (!canVectorizeInst(cast(GEPUser), AllocaUser))
187191 return false;
188192
189193 WorkList.push_back(GEPUser);
254258 if (UseInst && UseInst->getOpcode() == Instruction::PtrToInt)
255259 return false;
256260
261 if (StoreInst *SI = dyn_cast_or_null(UseInst)) {
262 // Reject if the stored value is not the pointer operand.
263 if (SI->getPointerOperand() != Val)
264 return false;
265 }
266
257267 if (!User->getType()->isPointerTy())
258268 continue;
259269
0 ; RUN: llc -march=amdgcn < %s | FileCheck -check-prefix=GCN %s
1
2 ; Pointer value is stored in a candidate for LDS usage.
3
4 ; GCN-LABEL: {{^}}stored_lds_pointer_value:
5 ; GCN: buffer_store_dword v
6 define void @stored_lds_pointer_value(float* addrspace(1)* %ptr) #0 {
7 %tmp = alloca float
8 store float 0.0, float *%tmp
9 store float* %tmp, float* addrspace(1)* %ptr
10 ret void
11 }
12
13 ; GCN-LABEL: {{^}}stored_lds_pointer_value_gep:
14 ; GCN-DAG: s_mov_b32 s{{[0-9]+}}, SCRATCH_RSRC_DWORD0
15 ; GCN-DAG: s_mov_b32 s{{[0-9]+}}, SCRATCH_RSRC_DWORD1
16 ; GCN: buffer_store_dword v
17 ; GCN: buffer_store_dword v
18 define void @stored_lds_pointer_value_gep(float* addrspace(1)* %ptr, i32 %idx) #0 {
19 bb:
20 %tmp = alloca float, i32 16
21 store float 0.0, float* %tmp
22 %tmp2 = getelementptr inbounds float, float* %tmp, i32 %idx
23 store float* %tmp2, float* addrspace(1)* %ptr
24 ret void
25 }
26
27 ; Pointer value is stored in a candidate for vector usage
28 ; GCN-LABEL: {{^}}stored_vector_pointer_value:
29 ; GCN-DAG: s_mov_b32 s{{[0-9]+}}, SCRATCH_RSRC_DWORD0
30 ; GCN-DAG: s_mov_b32 s{{[0-9]+}}, SCRATCH_RSRC_DWORD1
31 ; GCN: buffer_store_dword
32 ; GCN: buffer_store_dword
33 ; GCN: buffer_store_dword
34 ; GCN: buffer_store_dword
35 define void @stored_vector_pointer_value(i32* addrspace(1)* %out, i32 %index) {
36 entry:
37 %tmp0 = alloca [4 x i32]
38 %x = getelementptr [4 x i32], [4 x i32]* %tmp0, i32 0, i32 0
39 %y = getelementptr [4 x i32], [4 x i32]* %tmp0, i32 0, i32 1
40 %z = getelementptr [4 x i32], [4 x i32]* %tmp0, i32 0, i32 2
41 %w = getelementptr [4 x i32], [4 x i32]* %tmp0, i32 0, i32 3
42 store i32 0, i32* %x
43 store i32 1, i32* %y
44 store i32 2, i32* %z
45 store i32 3, i32* %w
46 %tmp1 = getelementptr [4 x i32], [4 x i32]* %tmp0, i32 0, i32 %index
47 store i32* %tmp1, i32* addrspace(1)* %out
48 ret void
49 }
50
51 attributes #0 = { nounwind }