Skip to content

Commit

Permalink
[Verifier][AMDGPU] No store to const addrspace
Browse files Browse the repository at this point in the history
  • Loading branch information
jofrn committed Sep 18, 2024
1 parent 5f02558 commit 7a77ede
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
17 changes: 17 additions & 0 deletions llvm/lib/IR/Verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4224,6 +4224,19 @@ void Verifier::visitLoadInst(LoadInst &LI) {
visitInstruction(LI);
}

static bool isConstantAddressSpace(unsigned AS) {
switch (AS) {
using namespace AMDGPUAS;
case CONSTANT_ADDRESS: case CONSTANT_ADDRESS_32BIT:
case CONSTANT_BUFFER_0: case CONSTANT_BUFFER_1: case CONSTANT_BUFFER_2: case CONSTANT_BUFFER_3:
case CONSTANT_BUFFER_4: case CONSTANT_BUFFER_5: case CONSTANT_BUFFER_6: case CONSTANT_BUFFER_7:
case CONSTANT_BUFFER_8: case CONSTANT_BUFFER_9: case CONSTANT_BUFFER_10: case CONSTANT_BUFFER_11:
case CONSTANT_BUFFER_12: case CONSTANT_BUFFER_13: case CONSTANT_BUFFER_14: case CONSTANT_BUFFER_15:
return true;
default: return false;
}
}

void Verifier::visitStoreInst(StoreInst &SI) {
PointerType *PTy = dyn_cast<PointerType>(SI.getOperand(1)->getType());
Check(PTy, "Store operand must be a pointer.", &SI);
Expand All @@ -4246,6 +4259,10 @@ void Verifier::visitStoreInst(StoreInst &SI) {
Check(SI.getSyncScopeID() == SyncScope::System,
"Non-atomic store cannot have SynchronizationScope specified", &SI);
}
if (TT.isAMDGPU()) {
Check(!isConstantAddressSpace(SI.getPointerAddressSpace()),
"Store cannot be to constant addrspace", &SI);
}
visitInstruction(SI);
}

Expand Down
9 changes: 9 additions & 0 deletions llvm/test/CodeGen/AMDGPU/const-store.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
; RUN: not llc -mtriple=amdgcn < %s |& FileCheck %s

define amdgpu_kernel void @store_const(ptr addrspace(4) %out, i32 %a, i32 %b) {
; CHECK: Store cannot be to constant addrspace
; CHECK-NEXT: store i32 %r, ptr addrspace(4) %out
%r = add i32 %a, %b
store i32 %r, ptr addrspace(4) %out
ret void
}

0 comments on commit 7a77ede

Please sign in to comment.