MachineSink::hasStoreBetween() determines that the code is "straight-line" by checking that From dominates To and To post-dominates From. Then it does a DFS walk starting at To, but only considers MBBs post-dominated by From.
The critical part this misses, is while the code is, in a certain sense of the word, "straight-line", it may still be part of a loop. To give a simple example:
From -> BB2 \ / A v v | To -> BB3
Here From dominates To, and To post-dominates From, and the current code would only check for a clobber in BB2, but not in BB3. (Unfortunately, I was not able to get MachineSink to trigger with a CFG that simple.)
What we actually want to determine is that no clobber is reverse-reachable from To (without going through From), so implement that, without the post-dominance check.
clang-format: please reformat the code