Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions llvm/lib/IR/Verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4224,6 +4224,33 @@ void Verifier::visitLoadInst(LoadInst &LI) {
visitInstruction(LI);
}

static bool isConstantAddressSpace(unsigned AS) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

constant address space is not an AMD only thing. I'm thinking probably we can split this function into target dependent (for example, to query whether an AS is a constant AS) and independent part.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would the independent part contain if we do not have a use case for it yet?

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 +4273,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
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test atomicrmw, cmpxchg, and a memset, memcpy? Also at least the addrspace(6) case