-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[DirectX] Legalize lifetime intrinsics for DXIL #148003
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
c9fbdba
7a2ae37
94fe78c
1b0aaef
1d81108
ce3c8d8
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
; RUN: opt -S --passes="print-dx-shader-flags" 2>&1 %s | FileCheck %s | ||
; RUN: llc %s --filetype=obj -o - | obj2yaml | FileCheck %s --check-prefix=DXC | ||
|
||
target triple = "dxil-pc-shadermodel6.7-library" | ||
|
||
; CHECK: ; Combined Shader Flags for Module | ||
; CHECK-NEXT: ; Shader Flags Value: 0x00000000 | ||
; CHECK-NEXT: ; | ||
; CHECK-NOT: ; Note: shader requires additional functionality: | ||
; CHECK-NOT: ; 64-Bit integer | ||
; CHECK-NOT: ; Note: extra DXIL module flags: | ||
; CHECK-NOT: ; | ||
; CHECK-NEXT: ; Shader Flags for Module Functions | ||
; CHECK-NEXT: ; Function lifetimes : 0x00000000 | ||
|
||
define void @lifetimes() #0 { | ||
%a = alloca [4 x i32], align 8 | ||
call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %a) | ||
call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %a) | ||
ret void | ||
} | ||
|
||
; Function Attrs: nounwind memory(argmem: readwrite) | ||
declare void @llvm.lifetime.start.p0(i64, ptr) #1 | ||
|
||
; Function Attrs: nounwind memory(argmem: readwrite) | ||
declare void @llvm.lifetime.end.p0(i64, ptr) #1 | ||
|
||
attributes #0 = { convergent norecurse nounwind "hlsl.export"} | ||
attributes #1 = { nounwind memory(argmem: readwrite) } | ||
|
||
; DXC: - Name: SFI0 | ||
; DXC-NEXT: Size: 8 | ||
; DXC-NOT: Flags: | ||
; DXC-NOT: Int64Ops: true | ||
; DXC: ... |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
; RUN: opt -S -passes='dxil-op-lower' -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s --check-prefixes=CHECK,CHECK-SM63 | ||
; RUN: opt -S -passes='dxil-op-lower' -mtriple=dxil-pc-shadermodel6.6-library %s | FileCheck %s --check-prefixes=CHECK,CHECK-SM66 | ||
; RUN: opt -S -dxil-op-lower -dxil-prepare -mtriple=dxil-pc-shadermodel6.6-library %s | FileCheck %s --check-prefixes=CHECK,CHECK-PREPARE | ||
|
||
; CHECK-LABEL: define void @test_legal_lifetime() { | ||
; | ||
|
@@ -15,6 +16,14 @@ | |
; CHECK-SM66-NEXT: store i32 0, ptr [[GEP]], align 4 | ||
; CHECK-SM66-NEXT: call void @llvm.lifetime.end.p0(i64 4, ptr nonnull [[ACCUM_I_FLAT]]) | ||
; | ||
; CHECK-PREPARE-NEXT: [[ACCUM_I_FLAT:%.*]] = alloca [1 x i32], align 4 | ||
; CHECK-PREPARE-NEXT: [[GEP:%.*]] = getelementptr i32, ptr [[ACCUM_I_FLAT]], i32 0 | ||
; CHECK-PREPARE-NEXT: [[BITCAST:%.*]] = bitcast ptr [[ACCUM_I_FLAT]] to ptr | ||
; CHECK-PREPARE-NEXT: call void @llvm.lifetime.start.p0(i64 4, ptr nonnull [[BITCAST]]) | ||
; CHECK-PREPARE-NEXT: store i32 0, ptr [[GEP]], align 4 | ||
; CHECK-PREPARE-NEXT: [[BITCAST:%.*]] = bitcast ptr [[ACCUM_I_FLAT]] to ptr | ||
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. Without adding too much complexity to the code, is it possible to re-use this for both lifetimes? You might be able to just iterate the users of Happy to just be told no. But wanted to make we thought of it 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. dxil-prepare inserts bitcasts for other instructions too, so I think this should be a suggestion for dxil-prepare as a whole and not just bitcasts for lifetimes intrinsics only. 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. generally bitcasts are "free" in that they don't have any runtime implementation cost, and for lifetime markers which also have no runtime implementation cost, they're usually not a big deal. They do have some tiny cost on binary size, but I'd say this probably isn't worth fixing. |
||
; CHECK-PREPARE-NEXT: call void @llvm.lifetime.end.p0(i64 4, ptr nonnull [[BITCAST]]) | ||
; | ||
; CHECK-NEXT: ret void | ||
; | ||
define void @test_legal_lifetime() { | ||
|
@@ -26,6 +35,22 @@ define void @test_legal_lifetime() { | |
ret void | ||
} | ||
|
||
; CHECK-PREPARE-DAG: attributes [[LIFETIME_ATTRS:#.*]] = { nounwind } | ||
|
||
; CHECK-PREPARE-DAG: ; Function Attrs: nounwind | ||
; CHECK-PREPARE-DAG: declare void @llvm.lifetime.start.p0(i64, ptr) [[LIFETIME_ATTRS]] | ||
|
||
; CHECK-PREPARE-DAG: ; Function Attrs: nounwind | ||
; CHECK-PREPARE-DAG: declare void @llvm.lifetime.end.p0(i64, ptr) [[LIFETIME_ATTRS]] | ||
|
||
; Function Attrs: nounwind memory(argmem: readwrite) | ||
declare void @llvm.lifetime.end.p0(i64, ptr) #0 | ||
|
||
; Function Attrs: nounwind memory(argmem: readwrite) | ||
declare void @llvm.lifetime.start.p0(i64, ptr) #0 | ||
|
||
attributes #0 = { nounwind memory(argmem: readwrite) } | ||
|
||
; Set the validator version to 1.6 | ||
!dx.valver = !{!0} | ||
!0 = !{i32 1, i32 6} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
; RUN: llc --filetype=obj %s -o - | dxil-dis -o - | FileCheck %s | ||
target triple = "dxil-unknown-shadermodel6.7-library" | ||
|
||
define void @test_lifetimes() { | ||
; CHECK-LABEL: test_lifetimes | ||
; CHECK-NEXT: [[ALLOCA:%.*]] = alloca [2 x i32], align 4 | ||
; CHECK-NEXT: [[GEP:%.*]] = getelementptr [2 x i32], [2 x i32]* [[ALLOCA]], i32 0, i32 0 | ||
; CHECK-NEXT: [[BITCAST:%.*]] = bitcast [2 x i32]* [[ALLOCA]] to i8* | ||
; CHECK-NEXT: call void @llvm.lifetime.start(i64 4, i8* nonnull [[BITCAST]]) | ||
; CHECK-NEXT: store i32 0, i32* [[GEP]], align 4 | ||
; CHECK-NEXT: [[BITCAST:%.*]] = bitcast [2 x i32]* [[ALLOCA]] to i8* | ||
; CHECK-NEXT: call void @llvm.lifetime.end(i64 4, i8* nonnull [[BITCAST]]) | ||
; CHECK-NEXT: ret void | ||
; | ||
%a = alloca [2 x i32], align 4 | ||
%gep = getelementptr [2 x i32], ptr %a, i32 0, i32 0 | ||
call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %a) | ||
store i32 0, ptr %gep, align 4 | ||
call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %a) | ||
ret void | ||
} | ||
|
||
; CHECK-DAG: attributes [[LIFETIME_ATTRS:#.*]] = { nounwind } | ||
|
||
; CHECK-DAG: ; Function Attrs: nounwind | ||
; CHECK-DAG: declare void @llvm.lifetime.start(i64, i8* nocapture) [[LIFETIME_ATTRS]] | ||
|
||
; CHECK-DAG: ; Function Attrs: nounwind | ||
; CHECK-DAG: declare void @llvm.lifetime.end(i64, i8* nocapture) [[LIFETIME_ATTRS]] | ||
|
||
; Function Attrs: nounwind memory(argmem: readwrite) | ||
declare void @llvm.lifetime.end.p0(i64, ptr) #0 | ||
|
||
; Function Attrs: nounwind memory(argmem: readwrite) | ||
declare void @llvm.lifetime.start.p0(i64, ptr) #0 | ||
|
||
attributes #0 = { nounwind memory(argmem: readwrite) } | ||
|
Uh oh!
There was an error while loading. Please reload this page.