Skip to content

[DirectX] Set function-level flag Int64Ops in DXIL Shader Flags Analysis #129089

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

Merged
merged 7 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 12 additions & 0 deletions llvm/lib/Target/DirectX/DXILShaderFlags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ void ModuleShaderFlags::updateFunctionFlags(ComputedShaderFlags &CSF,
}
}

if (!CSF.Int64Ops)
CSF.Int64Ops = I.getType()->isIntegerTy(64);

if (!CSF.Int64Ops) {
for (const Value *Op : I.operands()) {
if (Op->getType()->isIntegerTy(64)) {
CSF.Int64Ops = true;
break;
}
}
}

if (auto *II = dyn_cast<IntrinsicInst>(&I)) {
switch (II->getIntrinsicID()) {
default:
Expand Down
11 changes: 6 additions & 5 deletions llvm/test/CodeGen/DirectX/ShaderFlags/double-extensions.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
target triple = "dxil-pc-shadermodel6.7-library"

; CHECK: ; Combined Shader Flags for Module
; CHECK-NEXT: ; Shader Flags Value: 0x00000044
; CHECK-NEXT: ; Shader Flags Value: 0x00100044

; CHECK: ; Note: shader requires additional functionality:
; CHECK-NEXT: ; Double-precision floating point
; CHECK-NEXT: ; Double-precision extensions for 11.1
; CHECK-NEXT: ; 64-Bit integer
; CHECK-NEXT: ; Note: extra DXIL module flags:
; CHECK-NEXT: ;
; CHECK-NEXT: ; Shader Flags for Module Functions

;CHECK: ; Function top_level : 0x00000044
;CHECK: ; Function top_level : 0x00100044
define double @top_level() #0 {
%r = call double @test_uitofp_i64(i64 5)
ret double %r
Expand All @@ -25,13 +26,13 @@ define double @test_fdiv_double(double %a, double %b) #0 {
ret double %res
}

; CHECK: ; Function test_uitofp_i64 : 0x00000044
; CHECK: ; Function test_uitofp_i64 : 0x00100044
define double @test_uitofp_i64(i64 %a) #0 {
%r = uitofp i64 %a to double
ret double %r
}

; CHECK: ; Function test_sitofp_i64 : 0x00000044
; CHECK: ; Function test_sitofp_i64 : 0x00100044
define double @test_sitofp_i64(i64 %a) #0 {
%r = sitofp i64 %a to double
ret double %r
Expand All @@ -43,7 +44,7 @@ define i32 @test_fptoui_i32(double %a) #0 {
ret i32 %r
}

; CHECK: ; Function test_fptosi_i64 : 0x00000044
; CHECK: ; Function test_fptosi_i64 : 0x00100044
define i64 @test_fptosi_i64(double %a) #0 {
%r = fptosi double %a to i64
ret i64 %r
Expand Down
30 changes: 30 additions & 0 deletions llvm/test/CodeGen/DirectX/ShaderFlags/int64ops.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
; 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: 0x00100000
;CHECK-NEXT: ;
;CHECK-NEXT: ; Note: shader requires additional functionality:
;CHECK-NEXT: ; 64-Bit integer
;CHECK-NEXT: ; Note: extra DXIL module flags:
;CHECK-NEXT: ;
;CHECK-NEXT: ; Shader Flags for Module Functions
;CHECK-NEXT: ; Function add : 0x00100000

define i64 @add(i64 %a, i64 %b) #0 {
%sum = add i64 %a, %b
ret i64 %sum
}

attributes #0 = { convergent norecurse nounwind "hlsl.export"}

; DXC: - Name: SFI0
; DXC-NEXT: Size: 8
; DXC-NEXT: Flags:
; DXC-NOT: {{[A-Za-z]+: +true}}
; DXC: Int64Ops: true
; DXC-NOT: {{[A-Za-z]+: +true}}
; DXC: NextUnusedBit: false
; DXC: ...
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
target triple = "dxil-pc-shadermodel6.7-library"

; CHECK: ; Combined Shader Flags for Module
; CHECK-NEXT: ; Shader Flags Value: 0x00000044
; CHECK-NEXT: ; Shader Flags Value: 0x00100044
; CHECK-NEXT: ;
; CHECK-NEXT: ; Note: shader requires additional functionality:
; CHECK-NEXT: ; Double-precision floating point
; CHECK-NEXT: ; Double-precision extensions for 11.1
; CHECK-NEXT: ; 64-Bit integer
; CHECK-NEXT: ; Note: extra DXIL module flags:
; CHECK-NEXT: ;
; CHECK-NEXT: ; Shader Flags for Module Functions
Expand Down Expand Up @@ -55,13 +56,13 @@ define double @call_get_uitofp_flag(i32 noundef %0) local_unnamed_addr #0 {
ret double %2
}

; CHECK: ; Function call_get_fptoui_flag : 0x00000044
; CHECK: ; Function call_get_fptoui_flag : 0x00100044
define double @call_get_fptoui_flag(double noundef %0) local_unnamed_addr #0 {
%2 = tail call double @get_fptoui_flag(double noundef %0)
ret double %2
}

; CHECK: ; Function get_fptoui_flag : 0x00000044
; CHECK: ; Function get_fptoui_flag : 0x00100044
define double @get_fptoui_flag(double noundef %0) local_unnamed_addr #0 {
%2 = fcmp ugt double %0, 5.000000e+00
br i1 %2, label %6, label %3
Expand All @@ -81,7 +82,7 @@ define double @get_fptoui_flag(double noundef %0) local_unnamed_addr #0 {
ret double %10
}

; CHECK: ; Function get_sitofp_uitofp_flag : 0x00000044
; CHECK: ; Function get_sitofp_uitofp_flag : 0x00100044
define double @get_sitofp_uitofp_flag(i64 noundef %0) local_unnamed_addr #0 {
%2 = icmp ult i64 %0, 6
br i1 %2, label %3, label %7
Expand Down Expand Up @@ -154,7 +155,7 @@ define double @get_all_doubles_flags(i32 noundef %0) local_unnamed_addr #0 {
ret double %4
}

; CHECK: ; Function main : 0x00000044
; CHECK: ; Function main : 0x00100044
define i32 @main() local_unnamed_addr #0 {
%1 = tail call double @get_fptoui_flag(double noundef 1.000000e+00)
%2 = tail call double @get_sitofp_fdiv_flag(i32 noundef 4)
Expand Down