Eliminate Intermediate::replace()

With Reactor variables now merely tracking the last assigned rvalue if
used within a single basic block, we can avoid the unsafe replace()
operation on SpirvShader::Intermediate.

This effectively reverts
https://swiftshader-review.googlesource.com/c/SwiftShader/+/27769

Bug b/129356087
Bug b/128527271

Change-Id: Ibfafc6960ac7e10b898ff8804752b928a7fc1988
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/28109
Tested-by: Nicolas Capens <nicolascapens@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
diff --git a/src/Pipeline/SpirvShader.cpp b/src/Pipeline/SpirvShader.cpp
index e64c953..2106bdc 100644
--- a/src/Pipeline/SpirvShader.cpp
+++ b/src/Pipeline/SpirvShader.cpp
@@ -1277,14 +1277,13 @@
 		if (blockId != mainBlockId)
 		{
 			// Set the activeLaneMask.
-			Intermediate activeLaneMask(1);
-			activeLaneMask.move(0, SIMD::Int(0));
+			SIMD::Int activeLaneMask(0);
 			for (auto in : block.ins)
 			{
 				auto inMask = GetActiveLaneMaskEdge(state, in, blockId);
-				activeLaneMask.replace(0, activeLaneMask.Int(0) | inMask);
+				activeLaneMask |= inMask;
 			}
-			state->setActiveLaneMask(activeLaneMask.Int(0));
+			state->setActiveLaneMask(activeLaneMask);
 		}
 
 		EmitInstructions(block.begin(), block.end(), state);
@@ -3030,7 +3029,7 @@
 		auto type = getType(typeId);
 		auto objectId = Object::ID(insn.word(2));
 
-		auto &dst = routine->createIntermediate(objectId, type.sizeInComponents);
+		auto tmp = std::unique_ptr<SIMD::Int[]>(new SIMD::Int[type.sizeInComponents]);
 
 		bool first = true;
 		for (uint32_t w = 3; w < insn.wordCount(); w += 2)
@@ -3044,11 +3043,17 @@
 			for (uint32_t i = 0; i < type.sizeInComponents; i++)
 			{
 				auto inMasked = in.Int(i) & mask;
-				dst.replace(i, first ? inMasked : (dst.Int(i) | inMasked));
+				tmp[i] = first ? inMasked : (tmp[i] | inMasked);
 			}
 			first = false;
 		}
 
+		auto &dst = routine->createIntermediate(objectId, type.sizeInComponents);
+		for(uint32_t i = 0; i < type.sizeInComponents; i++)
+		{
+			dst.move(i, tmp[i]);
+		}
+
 		return EmitResult::Continue;
 	}
 
diff --git a/src/Pipeline/SpirvShader.hpp b/src/Pipeline/SpirvShader.hpp
index d7d4b4e..5bcef33 100644
--- a/src/Pipeline/SpirvShader.hpp
+++ b/src/Pipeline/SpirvShader.hpp
@@ -86,14 +86,6 @@
 		void move(uint32_t i, const RValue<SIMD::Int> &scalar)   { emplace(i, scalar.value); }
 		void move(uint32_t i, const RValue<SIMD::UInt> &scalar)  { emplace(i, scalar.value); }
 
-		void replace(uint32_t i, RValue<SIMD::Float> &&scalar) { replace(i, scalar.value); }
-		void replace(uint32_t i, RValue<SIMD::Int> &&scalar)   { replace(i, scalar.value); }
-		void replace(uint32_t i, RValue<SIMD::UInt> &&scalar)  { replace(i, scalar.value); }
-
-		void replace(uint32_t i, const RValue<SIMD::Float> &scalar) { replace(i, scalar.value); }
-		void replace(uint32_t i, const RValue<SIMD::Int> &scalar)   { replace(i, scalar.value); }
-		void replace(uint32_t i, const RValue<SIMD::UInt> &scalar)  { replace(i, scalar.value); }
-
 		// Value retrieval functions.
 		RValue<SIMD::Float> Float(uint32_t i) const
 		{
@@ -130,12 +122,6 @@
 			scalar[i] = value;
 		}
 
-		void replace(uint32_t i, rr::Value *value)
-		{
-			ASSERT(i < size);
-			scalar[i] = value;
-		}
-
 		rr::Value **const scalar;
 		uint32_t size;
 	};