Skip to content

Commit 9ba9689

Browse files
author
Junda Liu
authored
[SPIR-V] Set RValue for the result of bitfield extract emulation (#7200)
Otherwise, the result of bitfield extract emulation is treated as LValue and may have an extra OpLoad generated.
1 parent 909c552 commit 9ba9689

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

tools/clang/lib/SPIRV/SpirvBuilder.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,8 @@ SpirvInstruction *SpirvBuilder::createEmulatedBitFieldExtract(
994994
rightShift->setResultType(baseType);
995995
}
996996

997+
rightShift->setRValue(true);
998+
997999
return rightShift;
9981000
}
9991001

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %dxc -T cs_6_2 -E main -spirv -fcgl -enable-16bit-types %s | FileCheck %s
2+
3+
struct S1
4+
{
5+
uint16_t a : 8;
6+
};
7+
8+
S1 foo()
9+
{
10+
return (S1)0;
11+
}
12+
13+
[numthreads(1, 1, 1)]
14+
void main() {
15+
uint16_t test = foo().a;
16+
// CHECK: [[ptr:%[0-9]+]] = OpAccessChain %_ptr_Function_ushort %temp_var_S1 %int_0
17+
// CHECK: [[raw:%[0-9]+]] = OpLoad %ushort [[ptr]]
18+
// CHECK: [[tmp:%[0-9]+]] = OpShiftLeftLogical %ushort [[raw]] %uint_8
19+
// CHECK: [[out:%[0-9]+]] = OpShiftRightLogical %ushort [[tmp]] %uint_8
20+
// CHECK-NOT: OpLoad %ushort [[out]]
21+
// CHECK: OpStore %test [[out]]
22+
}

0 commit comments

Comments
 (0)