-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[AMDGPU][Verifier] Check address space of alloca
instruction
#135820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4395,6 +4395,11 @@ void Verifier::visitAllocaInst(AllocaInst &AI) { | |
verifySwiftErrorValue(&AI); | ||
} | ||
|
||
if (TT.isAMDGPU()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this check the triple? This should check the default alloca AS in the DL. Same for globals. Basically everything that has a dedicated AS in the DL should only be created in that AS. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is because of this folded comment #135820 (comment). There are some test cases that basically have |
||
Check(AI.getAddressSpace() == AMDGPUAS::PRIVATE_ADDRESS, | ||
"alloca on amdgpu must be in addrspace(5)", &AI); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be better to check it against the alloca addrspace from the data layout instead of hardcoding 5? My thinking is that this way we could extend this check to most other targets as well (mainly excluding wasm and any other that may be using multiple alloca address spaces). (Another more involved alternative would be to allow specifying multiple alloca address spaces in DL, and making the first the preferred one. Then this could be a target-independent check.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem with that is the datalayout isn't always right. Even if you have the triple, the right datalaoyut doesn't get pulled. e.g.
In this case DL.getAllocaAddrSpace() is 0 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think llc and opt do default to the correct data layout based on triple nowadays, but it's possible llvm-as doesn't do this, as a low level tool. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. llc yes, not opt I think. There are a bunch of tests with spurious datalayout = "A5" to compensate There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually does seem to work for opt now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nikic I'm thinking about how to update test cases after we extend DL. There are many test cases w/o triple nor data layout, but they have alloca in multiple ASs. After we extend DL, and assert that alloca must be in those ASs, how are we gonna deal with those test cases? Explicitly add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, that's what I'd expect to happen.
The target data layouts change all the time, this is not a problem in itself. Something I'm uncertain about with this approach is that this basically adds some information to the data layout that is only used for verification purposes. I don't think we have any other properties like that. Maybe that's a sign that it's not the right approach? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want it just to be for verification only? The point @arsenm made was that DL doesn't assert anything. If we can make it assert, it is gonna be more useful? Also, if we enforce alloca to be in specific AS(s), it is a form of assertion right? Therefore, we can use it in the middle end for optimization. Of course if a target accepts multiple ASs for alloca, we can't assert it must be in exact one, but for those only have one, we can assert. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -1 to making this a list in the DL. It's overly limiting and it's a lot of work for something we do not care about at all. KISS and just check == 5 for AMDGPU There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fine with leaving it at that for now. |
||
} | ||
|
||
visitInstruction(AI); | ||
} | ||
|
||
|
This file was deleted.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
; RUN: not llvm-as %s --disable-output 2>&1 | FileCheck %s | ||
|
||
target triple = "amdgcn-amd-amdhsa" | ||
|
||
; CHECK: alloca on amdgpu must be in addrspace(5) | ||
; CHECK-NEXT: %alloca.0 = alloca i32, align 4 | ||
; CHECK-NEXT: alloca on amdgpu must be in addrspace(5) | ||
; CHECK-NEXT: %alloca.1 = alloca i32, align 4, addrspace(1) | ||
; CHECK-NEXT: alloca on amdgpu must be in addrspace(5) | ||
; CHECK-NEXT: %alloca.2 = alloca i32, align 4, addrspace(2) | ||
; CHECK-NEXT: alloca on amdgpu must be in addrspace(5) | ||
; CHECK-NEXT: %alloca.3 = alloca i32, align 4, addrspace(3) | ||
; CHECK-NEXT: alloca on amdgpu must be in addrspace(5) | ||
; CHECK-NEXT: %alloca.4 = alloca i32, align 4, addrspace(4) | ||
; CHECK-NEXT: alloca on amdgpu must be in addrspace(5) | ||
; CHECK-NEXT: %alloca.6 = alloca i32, align 4, addrspace(6) | ||
; CHECK-NEXT: alloca on amdgpu must be in addrspace(5) | ||
; CHECK-NEXT: %alloca.7 = alloca i32, align 4, addrspace(7) | ||
; CHECK-NEXT: alloca on amdgpu must be in addrspace(5) | ||
; CHECK-NEXT: %alloca.8 = alloca i32, align 4, addrspace(8) | ||
; CHECK-NEXT: alloca on amdgpu must be in addrspace(5) | ||
; CHECK-NEXT: %alloca.9 = alloca i32, align 4, addrspace(9) | ||
define void @static_alloca() { | ||
entry: | ||
%alloca.0 = alloca i32, align 4 | ||
%alloca.1 = alloca i32, align 4, addrspace(1) | ||
%alloca.2 = alloca i32, align 4, addrspace(2) | ||
%alloca.3 = alloca i32, align 4, addrspace(3) | ||
%alloca.4 = alloca i32, align 4, addrspace(4) | ||
%alloca.5 = alloca i32, align 4, addrspace(5) | ||
shiltian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
%alloca.6 = alloca i32, align 4, addrspace(6) | ||
%alloca.7 = alloca i32, align 4, addrspace(7) | ||
%alloca.8 = alloca i32, align 4, addrspace(8) | ||
%alloca.9 = alloca i32, align 4, addrspace(9) | ||
ret void | ||
shiltian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
; CHECK: alloca on amdgpu must be in addrspace(5) | ||
; CHECK-NEXT: %alloca.0 = alloca i32, i32 %n, align 4 | ||
; CHECK-NEXT: alloca on amdgpu must be in addrspace(5) | ||
; CHECK-NEXT: %alloca.1 = alloca i32, i32 %n, align 4, addrspace(1) | ||
; CHECK-NEXT: alloca on amdgpu must be in addrspace(5) | ||
; CHECK-NEXT: %alloca.2 = alloca i32, i32 %n, align 4, addrspace(2) | ||
; CHECK-NEXT: alloca on amdgpu must be in addrspace(5) | ||
; CHECK-NEXT: %alloca.3 = alloca i32, i32 %n, align 4, addrspace(3) | ||
; CHECK-NEXT: alloca on amdgpu must be in addrspace(5) | ||
; CHECK-NEXT: %alloca.4 = alloca i32, i32 %n, align 4, addrspace(4) | ||
; CHECK-NEXT: alloca on amdgpu must be in addrspace(5) | ||
; CHECK-NEXT: %alloca.6 = alloca i32, i32 %n, align 4, addrspace(6) | ||
; CHECK-NEXT: alloca on amdgpu must be in addrspace(5) | ||
; CHECK-NEXT: %alloca.7 = alloca i32, i32 %n, align 4, addrspace(7) | ||
; CHECK-NEXT: alloca on amdgpu must be in addrspace(5) | ||
; CHECK-NEXT: %alloca.8 = alloca i32, i32 %n, align 4, addrspace(8) | ||
; CHECK-NEXT: alloca on amdgpu must be in addrspace(5) | ||
; CHECK-NEXT: %alloca.9 = alloca i32, i32 %n, align 4, addrspace(9) | ||
define void @dynamic_alloca_i32(i32 %n) { | ||
entry: | ||
%alloca.0 = alloca i32, i32 %n, align 4 | ||
%alloca.1 = alloca i32, i32 %n, align 4, addrspace(1) | ||
%alloca.2 = alloca i32, i32 %n, align 4, addrspace(2) | ||
%alloca.3 = alloca i32, i32 %n, align 4, addrspace(3) | ||
%alloca.4 = alloca i32, i32 %n, align 4, addrspace(4) | ||
%alloca.5 = alloca i32, i32 %n, align 4, addrspace(5) | ||
%alloca.6 = alloca i32, i32 %n, align 4, addrspace(6) | ||
%alloca.7 = alloca i32, i32 %n, align 4, addrspace(7) | ||
%alloca.8 = alloca i32, i32 %n, align 4, addrspace(8) | ||
%alloca.9 = alloca i32, i32 %n, align 4, addrspace(9) | ||
ret void | ||
} | ||
|
||
; CHECK: alloca on amdgpu must be in addrspace(5) | ||
; CHECK-NEXT: %alloca.0 = alloca i32, i64 %n, align 4 | ||
; CHECK-NEXT: alloca on amdgpu must be in addrspace(5) | ||
; CHECK-NEXT: %alloca.1 = alloca i32, i64 %n, align 4, addrspace(1) | ||
; CHECK-NEXT: alloca on amdgpu must be in addrspace(5) | ||
; CHECK-NEXT: %alloca.2 = alloca i32, i64 %n, align 4, addrspace(2) | ||
; CHECK-NEXT: alloca on amdgpu must be in addrspace(5) | ||
; CHECK-NEXT: %alloca.3 = alloca i32, i64 %n, align 4, addrspace(3) | ||
; CHECK-NEXT: alloca on amdgpu must be in addrspace(5) | ||
; CHECK-NEXT: %alloca.4 = alloca i32, i64 %n, align 4, addrspace(4) | ||
; CHECK-NEXT: alloca on amdgpu must be in addrspace(5) | ||
; CHECK-NEXT: %alloca.6 = alloca i32, i64 %n, align 4, addrspace(6) | ||
; CHECK-NEXT: alloca on amdgpu must be in addrspace(5) | ||
; CHECK-NEXT: %alloca.7 = alloca i32, i64 %n, align 4, addrspace(7) | ||
; CHECK-NEXT: alloca on amdgpu must be in addrspace(5) | ||
; CHECK-NEXT: %alloca.8 = alloca i32, i64 %n, align 4, addrspace(8) | ||
; CHECK-NEXT: alloca on amdgpu must be in addrspace(5) | ||
; CHECK-NEXT: %alloca.9 = alloca i32, i64 %n, align 4, addrspace(9) | ||
define void @dynamic_alloca_i64(i64 %n) { | ||
entry: | ||
%alloca.0 = alloca i32, i64 %n, align 4 | ||
%alloca.1 = alloca i32, i64 %n, align 4, addrspace(1) | ||
%alloca.2 = alloca i32, i64 %n, align 4, addrspace(2) | ||
%alloca.3 = alloca i32, i64 %n, align 4, addrspace(3) | ||
%alloca.4 = alloca i32, i64 %n, align 4, addrspace(4) | ||
%alloca.5 = alloca i32, i64 %n, align 4, addrspace(5) | ||
%alloca.6 = alloca i32, i64 %n, align 4, addrspace(6) | ||
%alloca.7 = alloca i32, i64 %n, align 4, addrspace(7) | ||
%alloca.8 = alloca i32, i64 %n, align 4, addrspace(8) | ||
%alloca.9 = alloca i32, i64 %n, align 4, addrspace(9) | ||
ret void | ||
} |
Uh oh!
There was an error while loading. Please reload this page.