Skip to content

Commit 8d1ba8b

Browse files
AnastaZIukPrzemog1
authored andcommitted
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
1 parent a8e8078 commit 8d1ba8b

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// RUN: %dxc -O3 -T lib_6_8 -HV 2021 -spirv -fcgl -fspv-target-env=universal1.5 %s | FileCheck %s
2+
3+
template <typename S> struct Trait;
4+
5+
template <> struct Trait<int64_t> {
6+
using type = int64_t;
7+
static const type value = -42;
8+
};
9+
10+
Trait<int64_t>::type get_s64_value() {
11+
return Trait<int64_t>::value;
12+
}
13+
14+
int64_t cvt_s64(int64_t x) { return int64_t(x); }
15+
16+
template <> struct Trait<uint64_t> {
17+
using type = uint64_t;
18+
static const type value = 1337ull;
19+
};
20+
21+
Trait<uint64_t>::type get_u64_value() {
22+
return Trait<uint64_t>::value;
23+
}
24+
25+
uint64_t cvt_u64(uint64_t x) { return uint64_t(x); }
26+
27+
// CHECK-LABEL: %testcase_s64 = OpFunction %long
28+
export int64_t testcase_s64(int x) {
29+
if (x == 2) {
30+
// CHECK: OpReturnValue %long_n42
31+
return int64_t(Trait<int64_t>::value);
32+
}
33+
else if (x == 4) {
34+
// CHECK: OpStore %param_var_x %long_n42
35+
// CHECK-NEXT: OpFunctionCall %long %cvt_s64 %param_var_x
36+
return cvt_s64(Trait<int64_t>::value);
37+
} else if (x == 8) {
38+
return get_s64_value();
39+
}
40+
return 0ll;
41+
}
42+
43+
// CHECK-LABEL: %testcase_u64 = OpFunction %ulong
44+
export uint64_t testcase_u64(int x) {
45+
if (x == 2) {
46+
// CHECK: OpReturnValue %ulong_1337
47+
return uint64_t(Trait<uint64_t>::value);
48+
}
49+
else if (x == 4) {
50+
// CHECK: OpStore %param_var_x_0 %ulong_1337
51+
// CHECK-NEXT: OpFunctionCall %ulong %cvt_u64 %param_var_x_0
52+
return cvt_u64(Trait<uint64_t>::value);
53+
} else if (x == 8) {
54+
return get_u64_value();
55+
}
56+
return 0ull;
57+
}
58+
59+
// CHECK-LABEL: %get_s64_value = OpFunction %long
60+
// CHECK-LABEL: %get_u64_value = OpFunction %ulong

0 commit comments

Comments
 (0)