Commit f72b89c4 by Ben Clayton

SpirvShader: Optimize pointer OOB masking

Reduces the amount of LLVM IR produced when the limits are compile-time known. Reduces full test execution time of dEQP-VK.ubo.random.all_out_of_order_offsets.45 by about half. For dEQP-VK.ubo.random.all_shared_buffer.48: • Reduces number of pre-opt LLVM IR instructions by about 40%. • Reduces full test execution time by about 30% Bug: b/135609394 Change-Id: I3c46d56910bb8373a355ab8d570d3093944afc84 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/33053Reviewed-by: 's avatarChris Forbes <chrisforbes@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarBen Clayton <bclayton@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent 0ea9fe43
...@@ -142,6 +142,22 @@ namespace sw ...@@ -142,6 +142,22 @@ namespace sw
{ {
ASSERT(accessSize > 0); ASSERT(accessSize > 0);
if (!hasDynamicOffsets && !hasDynamicLimit)
{
// Common fast paths.
if (hasStaticEqualOffsets())
{
return SIMD::Int((staticOffsets[0] + accessSize - 1 < staticLimit) ? 0xffffffff : 0);
}
static_assert(SIMD::Width == 4, "Expects SIMD::Width to be 4");
return SIMD::Int(
(staticOffsets[0] + accessSize - 1 < staticLimit) ? 0xffffffff : 0,
(staticOffsets[1] + accessSize - 1 < staticLimit) ? 0xffffffff : 0,
(staticOffsets[2] + accessSize - 1 < staticLimit) ? 0xffffffff : 0,
(staticOffsets[3] + accessSize - 1 < staticLimit) ? 0xffffffff : 0);
}
return CmpLT(offsets() + SIMD::Int(accessSize - 1), SIMD::Int(limit())); return CmpLT(offsets() + SIMD::Int(accessSize - 1), SIMD::Int(limit()));
} }
...@@ -178,15 +194,23 @@ namespace sw ...@@ -178,15 +194,23 @@ namespace sw
static_assert(SIMD::Width == 4, "Expects SIMD::Width to be 4"); static_assert(SIMD::Width == 4, "Expects SIMD::Width to be 4");
return rr::SignMask(~CmpEQ(o, o.yzwx)) == 0; return rr::SignMask(~CmpEQ(o, o.yzwx)) == 0;
} }
else return hasStaticEqualOffsets();
}
// Returns true if all offsets are compile-time static and are equal
// (N, N, N, N)
inline bool hasStaticEqualOffsets() const
{ {
if (hasDynamicOffsets)
{
return false;
}
for (int i = 1; i < SIMD::Width; i++) for (int i = 1; i < SIMD::Width; i++)
{ {
if (staticOffsets[i-1] != staticOffsets[i]) { return false; } if (staticOffsets[i-1] != staticOffsets[i]) { return false; }
} }
return true; return true;
} }
}
// Base address for the pointer, common across all lanes. // Base address for the pointer, common across all lanes.
rr::Pointer<rr::Byte> base; rr::Pointer<rr::Byte> base;
......
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