Simplify If/Else lowering

Previously we would append the 'begin' basic block with the conditional
branch only once we know whether or not there's a 'false' block separate
from the 'end' block (namely when executing the Else statement). We can
instead treat the 'false' block as the 'end' block itself when no Else
is encountered and simply continue emitting instructions in this block.

Note this removes the need to explicitly materialize all variables,
because that's taken care of by createCondBr().

Bug: b/180131694
Change-Id: I5c5c4373d1dc02991feffa69d4089b2c12054dc0
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/52988
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
Presubmit-Ready: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
diff --git a/src/Reactor/Reactor.hpp b/src/Reactor/Reactor.hpp
index bf5d8c0..922e21f 100644
--- a/src/Reactor/Reactor.hpp
+++ b/src/Reactor/Reactor.hpp
@@ -3510,32 +3510,18 @@
 {
 public:
 	IfElseData(RValue<Bool> cmp)
-	    : iteration(0)
 	{
-		condition = cmp.value();
-
-		beginBB = Nucleus::getInsertBlock();
 		trueBB = Nucleus::createBasicBlock();
-		falseBB = nullptr;
-		endBB = Nucleus::createBasicBlock();
+		falseBB = Nucleus::createBasicBlock();
+		endBB = falseBB;  // Until we encounter an Else statement, these are the same.
 
-		// The conditional branch won't be appended until we've reached the 'end'
-		// basic block, so we must materialize all variables now (i.e. emit store
-		// instrutions to write them to memory).
-		Variable::materializeAll();
-
+		Nucleus::createCondBr(cmp.value(), trueBB, falseBB);
 		Nucleus::setInsertBlock(trueBB);
 	}
 
 	~IfElseData()
 	{
 		Nucleus::createBr(endBB);
-
-		// Append the conditional branch instruction to the 'begin' basic block.
-		// Note that it's too late to materialize variables at this point.
-		Nucleus::setInsertBlock(beginBB);
-		Nucleus::createCondBr(condition, trueBB, falseBB ? falseBB : endBB);
-
 		Nucleus::setInsertBlock(endBB);
 	}
 
@@ -3553,19 +3539,17 @@
 
 	void elseClause()
 	{
+		endBB = Nucleus::createBasicBlock();
 		Nucleus::createBr(endBB);
 
-		falseBB = Nucleus::createBasicBlock();
 		Nucleus::setInsertBlock(falseBB);
 	}
 
 private:
-	Value *condition;
-	BasicBlock *beginBB;
-	BasicBlock *trueBB;
-	BasicBlock *falseBB;
-	BasicBlock *endBB;
-	int iteration;
+	BasicBlock *trueBB = nullptr;
+	BasicBlock *falseBB = nullptr;
+	BasicBlock *endBB = nullptr;
+	int iteration = 0;
 };
 
 #define For(init, cond, inc)                        \