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/+/38474
Tested-by: Antonio Maiorano <amaiorano@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
diff --git a/src/Reactor/ReactorUnitTests.cpp b/src/Reactor/ReactorUnitTests.cpp
index 584bd8b..dcfe961 100644
--- a/src/Reactor/ReactorUnitTests.cpp
+++ b/src/Reactor/ReactorUnitTests.cpp
@@ -1732,6 +1732,44 @@
 	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);
diff --git a/src/Reactor/SubzeroReactor.cpp b/src/Reactor/SubzeroReactor.cpp
index 1c94c5e..1ec7404 100644
--- a/src/Reactor/SubzeroReactor.cpp
+++ b/src/Reactor/SubzeroReactor.cpp
@@ -652,6 +652,9 @@
 
 		rr::optimize(::function);
 
+		::function->computeInOutEdges();
+		ASSERT(!::function->hasError());
+
 		::function->translate();
 		ASSERT(!::function->hasError());