From b71ef8217ca38d69328b5bb764d1ec2a54f65332 Mon Sep 17 00:00:00 2001 From: Arkadiusz Lachowicz <34793522+AnastaZIuk@users.noreply.github.com> Date: Mon, 1 Dec 2025 15:50:14 +0100 Subject: [PATCH 1/4] Add support for ulonglong and longlong types in const values handle update DeclResultIdMapper.cpp --- tools/clang/lib/SPIRV/DeclResultIdMapper.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/clang/lib/SPIRV/DeclResultIdMapper.cpp b/tools/clang/lib/SPIRV/DeclResultIdMapper.cpp index 33593e3f85..ca2eeea88a 100644 --- a/tools/clang/lib/SPIRV/DeclResultIdMapper.cpp +++ b/tools/clang/lib/SPIRV/DeclResultIdMapper.cpp @@ -4912,12 +4912,19 @@ bool DeclResultIdMapper::tryToCreateConstantVar(const ValueDecl *decl) { constVal = spvBuilder.getConstantInt(astContext.UnsignedIntTy, val->getInt()); break; + case BuiltinType::ULongLong: // uint64_t + constVal = + spvBuilder.getConstantInt(astContext.UnsignedLongLongTy, val->getInt()); + break; case BuiltinType::Short: // int16_t constVal = spvBuilder.getConstantInt(astContext.ShortTy, val->getInt()); break; case BuiltinType::Int: // int32_t constVal = spvBuilder.getConstantInt(astContext.IntTy, val->getInt()); break; + case BuiltinType::LongLong: // int64_t + constVal = spvBuilder.getConstantInt(astContext.LongLongTy, val->getInt()); + break; case BuiltinType::Half: // float16_t constVal = spvBuilder.getConstantFloat(astContext.HalfTy, val->getFloat()); break; From a9f2b36a0a52d9c6fb96c6f7db38fadfaa7e27d4 Mon Sep 17 00:00:00 2001 From: Arkadiusz Lachowicz <34793522+AnastaZIuk@users.noreply.github.com> Date: Mon, 1 Dec 2025 18:58:34 +0100 Subject: [PATCH 2/4] Update Release Notes Added support for long long and unsigned long long compile-time constant evaluation, addressing issue #7952. --- docs/ReleaseNotes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/ReleaseNotes.md b/docs/ReleaseNotes.md index 4fdb82f2ca..44d01d018b 100644 --- a/docs/ReleaseNotes.md +++ b/docs/ReleaseNotes.md @@ -23,6 +23,7 @@ The included licenses apply to the following files: - Fixed regression: [#7508](https://github.com/microsoft/DirectXShaderCompiler/issues/7508) crash when calling `Load` with `status`. - Header file `dxcpix.h` was added to the release package. - Moved Linear Algebra (Cooperative Vector) DXIL Opcodes to experimental Shader Model 6.10 +- Added support for `long long` and `unsigned long long` compile-time constant evaluation, fixes [#7952](https://github.com/microsoft/DirectXShaderCompiler/issues/7952). ### Version 1.8.2505 From 75babd5fa9a17c2ea733a34a9121685d495a0933 Mon Sep 17 00:00:00 2001 From: Arkadiusz Lachowicz <34793522+AnastaZIuk@users.noreply.github.com> Date: Mon, 1 Dec 2025 22:15:19 +0100 Subject: [PATCH 3/4] Add SPIR-V const-folding regression test for int64_t and uint64_t perform tests on new `tools\clang\test\CodeGenSPIRV\spv.constant-folding.template.int64.hlsl` with `llvm-lit.py`, before the fix and after --- .../spv.constant-folding.template.int64.hlsl | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 tools/clang/test/CodeGenSPIRV/spv.constant-folding.template.int64.hlsl diff --git a/tools/clang/test/CodeGenSPIRV/spv.constant-folding.template.int64.hlsl b/tools/clang/test/CodeGenSPIRV/spv.constant-folding.template.int64.hlsl new file mode 100644 index 0000000000..2555e442de --- /dev/null +++ b/tools/clang/test/CodeGenSPIRV/spv.constant-folding.template.int64.hlsl @@ -0,0 +1,60 @@ +// RUN: %dxc -O3 -T lib_6_8 -HV 2021 -spirv -fcgl -fspv-target-env=universal1.5 %s | FileCheck %s + +template struct Trait; + +template <> struct Trait { + using type = int64_t; + static const type value = -42; +}; + +Trait::type get_s64_value() { + return Trait::value; +} + +int64_t cvt_s64(int64_t x) { return int64_t(x); } + +template <> struct Trait { + using type = uint64_t; + static const type value = 1337ull; +}; + +Trait::type get_u64_value() { + return Trait::value; +} + +uint64_t cvt_u64(uint64_t x) { return uint64_t(x); } + +// CHECK-LABEL: %testcase_s64 = OpFunction %long +export int64_t testcase_s64(int x) { + if (x == 2) { + // CHECK: OpReturnValue %long_n42 + return int64_t(Trait::value); + } + else if (x == 4) { + // CHECK: OpStore %param_var_x %long_n42 + // CHECK-NEXT: OpFunctionCall %long %cvt_s64 %param_var_x + return cvt_s64(Trait::value); + } else if (x == 8) { + return get_s64_value(); + } + return 0ll; +} + +// CHECK-LABEL: %testcase_u64 = OpFunction %ulong +export uint64_t testcase_u64(int x) { + if (x == 2) { + // CHECK: OpReturnValue %ulong_1337 + return uint64_t(Trait::value); + } + else if (x == 4) { + // CHECK: OpStore %param_var_x_0 %ulong_1337 + // CHECK-NEXT: OpFunctionCall %ulong %cvt_u64 %param_var_x_0 + return cvt_u64(Trait::value); + } else if (x == 8) { + return get_u64_value(); + } + return 0ull; +} + +// CHECK-LABEL: %get_s64_value = OpFunction %long +// CHECK-LABEL: %get_u64_value = OpFunction %ulong From 87226fe78fcd2362fefceedd2217c9c56bb7a9bd Mon Sep 17 00:00:00 2001 From: Przemog1 Date: Wed, 3 Dec 2025 16:15:10 +0100 Subject: [PATCH 4/4] Modified the spv.constant-folding.template.int64.hlsl test --- .../spv.constant-folding.template.int64.hlsl | 72 +++++-------------- 1 file changed, 18 insertions(+), 54 deletions(-) diff --git a/tools/clang/test/CodeGenSPIRV/spv.constant-folding.template.int64.hlsl b/tools/clang/test/CodeGenSPIRV/spv.constant-folding.template.int64.hlsl index 2555e442de..58ab3a0e99 100644 --- a/tools/clang/test/CodeGenSPIRV/spv.constant-folding.template.int64.hlsl +++ b/tools/clang/test/CodeGenSPIRV/spv.constant-folding.template.int64.hlsl @@ -1,60 +1,24 @@ -// RUN: %dxc -O3 -T lib_6_8 -HV 2021 -spirv -fcgl -fspv-target-env=universal1.5 %s | FileCheck %s +// RUN: %dxc %s -T lib_6_8 -E main -spirv -enable-16bit-types -template struct Trait; +// CHECK-DAG: %ulong = OpTypeInt 64 0 +// CHECK-DAG: %long = OpTypeInt 64 1 -template <> struct Trait { - using type = int64_t; - static const type value = -42; +template struct S { + static const T value = 0; }; -Trait::type get_s64_value() { - return Trait::value; +// CHECK: %u = OpFunction %void None +[shader("vertex")] +uint64_t u() : A +{ + // CHECK: OpStore %out_var_A %ulong_0 + return S::value; } -int64_t cvt_s64(int64_t x) { return int64_t(x); } - -template <> struct Trait { - using type = uint64_t; - static const type value = 1337ull; -}; - -Trait::type get_u64_value() { - return Trait::value; -} - -uint64_t cvt_u64(uint64_t x) { return uint64_t(x); } - -// CHECK-LABEL: %testcase_s64 = OpFunction %long -export int64_t testcase_s64(int x) { - if (x == 2) { - // CHECK: OpReturnValue %long_n42 - return int64_t(Trait::value); - } - else if (x == 4) { - // CHECK: OpStore %param_var_x %long_n42 - // CHECK-NEXT: OpFunctionCall %long %cvt_s64 %param_var_x - return cvt_s64(Trait::value); - } else if (x == 8) { - return get_s64_value(); - } - return 0ll; -} - -// CHECK-LABEL: %testcase_u64 = OpFunction %ulong -export uint64_t testcase_u64(int x) { - if (x == 2) { - // CHECK: OpReturnValue %ulong_1337 - return uint64_t(Trait::value); - } - else if (x == 4) { - // CHECK: OpStore %param_var_x_0 %ulong_1337 - // CHECK-NEXT: OpFunctionCall %ulong %cvt_u64 %param_var_x_0 - return cvt_u64(Trait::value); - } else if (x == 8) { - return get_u64_value(); - } - return 0ull; -} - -// CHECK-LABEL: %get_s64_value = OpFunction %long -// CHECK-LABEL: %get_u64_value = OpFunction %ulong +// CHECK: %s = OpFunction %void None +[shader("vertex")] +int64_t s() : B +{ + // CHECK: OpStore %out_var_A %long_0 + return S::value; +} \ No newline at end of file