[LLVM16] Fix crash when findLSB is called with 0.
With LLVM 16, dEQP-VK.graphicsfuzz.cov-inc-array-element-loop-lsb
started to crash.
It appears that Swiftshader was generating a Cttz call
(https://llvm.org/docs/LangRef.html#llvm-cttz-intrinsic)
with <is_zero_poison> set to true, even though the parameter
can be zero. This led to undefined behavior.
With the change in SpirvShaderGLSLstd450.cpp, the test does not
crash anymore.
While searching for more instances of this bug, the call in
SpirvShaderGroup.cpp was found.
The change in SpirvShaderGroup.cpp is unrelated to the dEQP failure.
b/272710814
Change-Id: I912a770ee808a54a59eca1da45b41636708e80bb
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/71508
Tested-by: Jean-François Geyelin <jif@google.com>
Commit-Queue: Jean-François Geyelin <jif@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
diff --git a/src/Pipeline/SpirvShaderGLSLstd450.cpp b/src/Pipeline/SpirvShaderGLSLstd450.cpp
index 3a5a6ca..1286066 100644
--- a/src/Pipeline/SpirvShaderGLSLstd450.cpp
+++ b/src/Pipeline/SpirvShaderGLSLstd450.cpp
@@ -866,7 +866,7 @@
for(auto i = 0u; i < type.componentCount; i++)
{
auto v = val.UInt(i);
- dst.move(i, Cttz(v, true) | CmpEQ(v, SIMD::UInt(0)));
+ dst.move(i, Cttz(v, false) | CmpEQ(v, SIMD::UInt(0)));
}
}
break;
diff --git a/src/Pipeline/SpirvShaderGroup.cpp b/src/Pipeline/SpirvShaderGroup.cpp
index c06d8a6..a3711a9 100644
--- a/src/Pipeline/SpirvShaderGroup.cpp
+++ b/src/Pipeline/SpirvShaderGroup.cpp
@@ -306,7 +306,7 @@
ASSERT(type.componentCount == 1);
ASSERT(shader.getObjectType(valueId).componentCount == 4);
Operand value(shader, *this, valueId);
- dst.move(0, Cttz(value.UInt(0) & SIMD::UInt(15), true));
+ dst.move(0, Cttz(value.UInt(0) & SIMD::UInt(15), false));
}
break;