Commit 7ffda5b3 by Antonio Maiorano

Subzero: fix invalid register allocation

Subzero would generate invalid code during register allocation in certain instances related to incorrect liveness analysis. With the help of Jim Stichnoth, we identified that "computeInOutEdges" was never being called, so, as Jim put it: "Because control-flow information is not available in InEdges and OutEdges, liveness analysis essentially does block-local liveness instead of global liveness." As a result, values would get incorrectly assigned to registers. The ExtractFromRValue unit test demonstrates this bug. Without the call to computeInOutEdges, the Extract(v, 1) would return the wrong result. Bug: b/144688789 Change-Id: Iad7f7bf9dec74f628120003d316480d83b9fa4f1 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/38474Tested-by: 's avatarAntonio Maiorano <amaiorano@google.com> Reviewed-by: 's avatarBen Clayton <bclayton@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent 01386d17
......@@ -1732,6 +1732,44 @@ TEST(ReactorUnitTests, Coroutines_Parameters)
EXPECT_EQ(out, 99);
}
TEST(ReactorUnitTests, ExtractFromRValue)
{
Function<Void(Pointer<Int4> values, Pointer<Int4> result)> function;
{
Pointer<Int4> vIn = function.Arg<0>();
Pointer<Int4> resultIn = function.Arg<1>();
RValue<Int4> v = *vIn;
Int4 result(678);
If(Extract(v, 0) == 42)
{
result = Insert(result, 1, 0);
}
If(Extract(v, 1) == 42)
{
result = Insert(result, 1, 1);
}
*resultIn = result;
Return();
}
auto routine = function("one");
auto entry = (void(*)(int*, int*))routine->getEntry();
int v[4] = { 42, 42, 42, 42 };
int result[4] = { 99, 99, 99, 99 };
entry(v, result);
EXPECT_EQ(result[0], 1);
EXPECT_EQ(result[1], 1);
EXPECT_EQ(result[2], 678);
EXPECT_EQ(result[3], 678);
}
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
......
......@@ -652,6 +652,9 @@ namespace rr
rr::optimize(::function);
::function->computeInOutEdges();
ASSERT(!::function->hasError());
::function->translate();
ASSERT(!::function->hasError());
......
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