Skip to content

Commit a099028

Browse files
committed
[Verifier][AMDGPU] No store to const addrspace
Ensure store to const addrspace is not allowed by IR Verifier.
1 parent 5f02558 commit a099028

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

llvm/lib/IR/Verifier.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4224,6 +4224,33 @@ void Verifier::visitLoadInst(LoadInst &LI) {
42244224
visitInstruction(LI);
42254225
}
42264226

4227+
static bool isConstantAddressSpace(unsigned AS) {
4228+
switch (AS) {
4229+
using namespace AMDGPUAS;
4230+
case CONSTANT_ADDRESS:
4231+
case CONSTANT_ADDRESS_32BIT:
4232+
case CONSTANT_BUFFER_0:
4233+
case CONSTANT_BUFFER_1:
4234+
case CONSTANT_BUFFER_2:
4235+
case CONSTANT_BUFFER_3:
4236+
case CONSTANT_BUFFER_4:
4237+
case CONSTANT_BUFFER_5:
4238+
case CONSTANT_BUFFER_6:
4239+
case CONSTANT_BUFFER_7:
4240+
case CONSTANT_BUFFER_8:
4241+
case CONSTANT_BUFFER_9:
4242+
case CONSTANT_BUFFER_10:
4243+
case CONSTANT_BUFFER_11:
4244+
case CONSTANT_BUFFER_12:
4245+
case CONSTANT_BUFFER_13:
4246+
case CONSTANT_BUFFER_14:
4247+
case CONSTANT_BUFFER_15:
4248+
return true;
4249+
default:
4250+
return false;
4251+
}
4252+
}
4253+
42274254
void Verifier::visitStoreInst(StoreInst &SI) {
42284255
PointerType *PTy = dyn_cast<PointerType>(SI.getOperand(1)->getType());
42294256
Check(PTy, "Store operand must be a pointer.", &SI);
@@ -4246,6 +4273,10 @@ void Verifier::visitStoreInst(StoreInst &SI) {
42464273
Check(SI.getSyncScopeID() == SyncScope::System,
42474274
"Non-atomic store cannot have SynchronizationScope specified", &SI);
42484275
}
4276+
if (TT.isAMDGPU()) {
4277+
Check(!isConstantAddressSpace(SI.getPointerAddressSpace()),
4278+
"Store cannot be to constant addrspace", &SI);
4279+
}
42494280
visitInstruction(SI);
42504281
}
42514282

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
; RUN: not llc -mtriple=amdgcn < %s |& FileCheck %s
2+
3+
define amdgpu_kernel void @store_const(ptr addrspace(4) %out, i32 %a, i32 %b) {
4+
; CHECK: Store cannot be to constant addrspace
5+
; CHECK-NEXT: store i32 %r, ptr addrspace(4) %out
6+
%r = add i32 %a, %b
7+
store i32 %r, ptr addrspace(4) %out
8+
ret void
9+
}

0 commit comments

Comments
 (0)