But not because of "That is, if a function terminates early, you're not evaluating the expressions unnecessarily, no?"
If the function terminates early, and you've moved the expression computation before or after an early termination point, you've by definition changed what paths it is computed on (unless it was already computed there). That is not legal in all cases (it's speculative PRE/PDE)
PRE and VBE (which is what this is) guarantee that the expression is still computed at on the same paths. They just make it so it's computed once.
What is happening here is really a size optimization. If it can prove that it is always executed, it has one copy of the computation, instead of multiple ones.
This is identical to what LLVM's load-store motion does for loads, except for all expressions and not just loads.
This is identical to what LLVM's load-store motion does for
loads, except for all expressions and not just loads.
It's actually not.
It's what GVNHoist does, but not MLSM.
MLSM only handles diamonds.In any case, because the GCC implementation is written on top of a sane PRE infrastructure, it is like 50 lines of code to do this :)
It's actually not. It's what GVNHoist does, but not MLSM. MLSM only handles diamonds.
Fine, it's what MLSM aspires to: http://llvm-cs.pcc.me.uk/lib/Transforms/Scalar/MergedLoadSto... (:Maybe it happens, but it ain't gonna happen with anything like this code :)