Skip to content

Commit 8fe99be

Browse files
authored
[SPIR-V] Fix firstbit{high,low} elem check (#6607)
The code gen for firstbithigh and -low was incorrectly checking the size of the full (possibly composite) type rather than the element size. This is now fixed, and I've also switch the error check from whether the element type is == 64-bit to != 32-bit, so that it matches the current limitations of the GLSL extended instructions. https://registry.khronos.org/SPIR-V/specs/unified1/GLSL.std.450.html#:~:text=%3Cid%3E%0AValue-,FindSMsb,-Signed%2Dinteger%20most Related to #4702
1 parent 4273354 commit 8fe99be

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

tools/clang/lib/SPIRV/SpirvEmitter.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8998,8 +8998,10 @@ SpirvEmitter::processIntrinsicFirstbit(const CallExpr *callExpr,
89988998
const SourceRange srcRange = callExpr->getSourceRange();
89998999
const QualType argType = callExpr->getArg(0)->getType();
90009000

9001-
if (astContext.getTypeSize(argType) == 64) {
9002-
emitError("%0 is not yet implemented for 64-bit width components when "
9001+
const uint32_t bitwidth = getElementSpirvBitwidth(
9002+
astContext, argType, spirvOptions.enable16BitTypes);
9003+
if (bitwidth != 32) {
9004+
emitError("%0 is currently limited to 32-bit width components when "
90039005
"targetting SPIR-V",
90049006
srcLoc)
90059007
<< getFunctionOrOperatorName(callee, true);

tools/clang/test/CodeGenSPIRV/intrinsics.firstbithigh.64bit.hlsl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
void main() {
44
uint64_t uint_1;
5+
int64_t2 int_2;
6+
// CHECK: error: firstbithigh is currently limited to 32-bit width components when targetting SPIR-V
57
int fbh = firstbithigh(uint_1);
8+
// CHECK: error: firstbithigh is currently limited to 32-bit width components when targetting SPIR-V
9+
int64_t2 fbh2 = firstbithigh(int_2);
610
}
7-
8-
// CHECK: error: firstbithigh is not yet implemented for 64-bit width components when targetting SPIR-V

tools/clang/test/CodeGenSPIRV/intrinsics.firstbithigh.hlsl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ void main() {
66
int sint_1;
77
int4 sint_4;
88
uint uint_1;
9+
uint2 uint_2;
910
uint4 uint_4;
1011

1112
// CHECK: [[sint_1:%[0-9]+]] = OpLoad %int %sint_1
@@ -25,6 +26,11 @@ void main() {
2526
// CHECK: OpStore %ufbh [[msb]]
2627
uint ufbh = firstbithigh(uint_1);
2728

29+
// CHECK: [[uint_2:%[0-9]+]] = OpLoad %v2uint %uint_2
30+
// CHECK: [[msb:%[0-9]+]] = OpExtInst %v2uint [[glsl]] FindUMsb [[uint_2]]
31+
// CHECK: OpStore %ufbh2 [[msb]]
32+
uint2 ufbh2 = firstbithigh(uint_2);
33+
2834
// CHECK: [[uint_4:%[0-9]+]] = OpLoad %v4uint %uint_4
2935
// CHECK: [[msb:%[0-9]+]] = OpExtInst %v4uint [[glsl]] FindUMsb [[uint_4]]
3036
// CHECK: OpStore %ufbh4 [[msb]]

tools/clang/test/CodeGenSPIRV/intrinsics.firstbitlow.64bit.hlsl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
void main() {
44
uint64_t uint_1;
5+
// CHECK: error: firstbitlow is currently limited to 32-bit width components when targetting SPIR-V
56
int fbl = firstbitlow(uint_1);
67
}
7-
8-
// CHECK: error: firstbitlow is not yet implemented for 64-bit width components when targetting SPIR-V

0 commit comments

Comments
 (0)