[NewOptimizer] Refactor phinode codegen
Turns out the old approach we used didn't work, because it was possible
for the processing of one phi node to clobber the operands of another (e.g.
in a loop where one phi node depends on another). Fix this by using two
buffers. This isn't great, but hopefully LLVM should do ok at it. If
not, we can fix LLVM or try to be smarter.