When a block has no terminator instructions, getFirstTerminator() returns end(), which can't be used in dominance checks. Check dominance for phi operands separately.
Also, remove some bits from WebAssemblyRegStackify.cpp that were causing trouble on the same testcase; they were left behind from an earlier experiment.
I don't really understand what this arithmetic on the MachineOperands actually means.
I guess it's just trying to find which operand on Where is the use of MI.
Actually there's also nothing that explicitly says what the pass even does.
IIUC we are attempting to find uses of the stored value and make them uses of the result of the store instead (which we can do if the store dominates the use), so maybe it should say that somewhere.