Commit b162fcf9 by Nicolas Capens Committed by Nicolas Capens

Work around MemorySanitizer movmsk false positives

MemorySanitizer does not recognize the x86 movmskps and pmovmskb instructions. In such cases it falls back to checking all input operands for uninitialized bits. This causes false positives specifically with Reactor's Byte8 type which is often loaded from memory, leaving the upper 64-bit of an SSE register undefined. This change masks out the unused parts of the input vector, leaving just the sign bits. Bug: b/172238865 Change-Id: I50c921a7ff8a4ebdba89136bb82c9f46ccdc3769 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/54268 Kokoro-Result: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com>
parent be169ef3
......@@ -3960,12 +3960,32 @@ RValue<Int4> pmaddwd(RValue<Short8> x, RValue<Short8> y)
RValue<Int> movmskps(RValue<Float4> x)
{
return RValue<Int>(createInstruction(llvm::Intrinsic::x86_sse_movmsk_ps, x.value()));
Value *v = x.value();
// TODO(b/172238865): MemorySanitizer does not support movmsk instructions,
// which makes it look at the entire 128-bit input for undefined bits. Mask off
// just the sign bits to avoid false positives.
if(__has_feature(memory_sanitizer))
{
v = As<Float4>(As<Int4>(v) & Int4(0x80000000u)).value();
}
return RValue<Int>(createInstruction(llvm::Intrinsic::x86_sse_movmsk_ps, v));
}
RValue<Int> pmovmskb(RValue<Byte8> x)
{
return RValue<Int>(createInstruction(llvm::Intrinsic::x86_sse2_pmovmskb_128, x.value())) & 0xFF;
Value *v = x.value();
// TODO(b/172238865): MemorySanitizer does not support movmsk instructions,
// which makes it look at the entire 128-bit input for undefined bits. Mask off
// just the sign bits in the lower 64-bit vector to avoid false positives.
if(__has_feature(memory_sanitizer))
{
v = As<Byte16>(As<Int4>(v) & Int4(0x80808080u, 0x80808080u, 0, 0)).value();
}
return RValue<Int>(createInstruction(llvm::Intrinsic::x86_sse2_pmovmskb_128, v)) & 0xFF;
}
RValue<Int4> pmovzxbd(RValue<Byte16> x)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment