Skip to content

Commit 912f91d

Browse files
Firestar99LegNeato
authored andcommitted
black_box: disassemble compiletest
1 parent e5290b3 commit 912f91d

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

tests/compiletests/ui/lang/core/intrinsics/black_box.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Test black_box intrinsic
22
// build-pass
3+
// compile-flags: -C llvm-args=--disassemble-fn=black_box::disassemble
34

45
#![allow(internal_features)]
56
#![feature(core_intrinsics)]
@@ -9,7 +10,14 @@ use core::hint::black_box;
910
use spirv_std::spirv;
1011

1112
#[spirv(compute(threads(1)))]
12-
pub fn main() {
13+
pub fn main(#[spirv(descriptor_set = 0, binding = 0, storage_buffer)] out: &mut [u32]) {
14+
let result = disassemble();
15+
for i in 0..result.len() {
16+
out[i] = result[i];
17+
}
18+
}
19+
20+
pub fn disassemble() -> [u32; 8] {
1321
// Test with various types
1422
let x = 42i32;
1523
let y = black_box(x);
@@ -26,4 +34,15 @@ pub fn main() {
2634
// Test with references
2735
let data = 100u32;
2836
let ref_data = black_box(&data);
37+
38+
[
39+
y as u32,
40+
f32::to_bits(b),
41+
w[0],
42+
w[1],
43+
w[2],
44+
w[3],
45+
result,
46+
*ref_data,
47+
]
2948
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
warning: black_box intrinsic does not prevent optimization in Rust GPU
22

3+
%1 = OpFunction %2 None %3
4+
%4 = OpLabel
5+
OpLine %5 34 17
6+
%6 = OpIAdd %7 %8 %9
7+
OpLine %5 40 5
8+
%10 = OpBitcast %7 %11
9+
OpLine %12 1092 17
10+
%13 = OpBitcast %7 %14
11+
OpLine %5 40 4
12+
%15 = OpCompositeConstruct %2 %10 %13 %16 %17 %18 %19 %6 %20
13+
OpNoLine
14+
OpReturnValue %15
15+
OpFunctionEnd
316
warning: 1 warning emitted
417

0 commit comments

Comments
 (0)