News for hackers. Stuff that matters.
Re:GCC 7 Release Series – Changes, New Features, and Fixes by mindleyhilner on Sunday April 09, 2017 @12:44PM (#14073116)

  It attempts to move evaluation of expressions executed on all paths to the function *exit* as early as possible, which helps primarily for code size, but can be useful for speed of generated code as well. [Emphasis added.]
Typo? PRE hoists upwards, so it would make sense to move closer to entry, not exit.
Re:GCC 7 Release Series – Changes, New Features, and Fixes by DannyBee on Sunday April 09, 2017 @01:05PM (#14073229)
No, it's correct. It's saying "if they are always computed, we move them up".

IE

  if (a)
    foo = a + b
  else b 
    foo = a + b
  ->
  foo = a+b
  if (a)
  else (b)
Re:GCC 7 Release Series – Changes, New Features, and Fixes by fenollp on Sunday April 09, 2017 @02:05PM (#14073519)
Possible side effects correction:

    ->
      if (a)
      else (b)
      foo = a+b
Re:GCC 7 Release Series – Changes, New Features, and Fixes by mindleyhilner on Sunday April 09, 2017 @01:09PM (#14073242)
How do you move up towards exit?
Re:GCC 7 Release Series – Changes, New Features, and Fixes by evilpie on Sunday April 09, 2017 @01:29PM (#14073338)
I think you have to read it like "executed on >all paths to the function exit< as early as possible". As in, if you have an expression that is always executed regardless which path you take before returning. It's useful to move that expression upwards instead of having copies on the different paths to the function exit.
Re:GCC 7 Release Series – Changes, New Features, and Fixes by sanjoy_das on Sunday April 09, 2017 @05:02PM (#14074346)
My guess is that they meant "up" in the sense of "up in post dominator tree".
Re:GCC 7 Release Series – Changes, New Features, and Fixes by bastawhiz on Sunday April 09, 2017 @12:59PM (#14073191)
Naive question: if you move towards the exit of a function, wouldn't that be beneficial? That is, if a function terminates early, you're not evaluating the expressions unnecessarily, no?
Re:GCC 7 Release Series – Changes, New Features, and Fixes by DannyBee on Sunday April 09, 2017 @01:09PM (#14073241)
In practice, you want to do both.IE hoist everything you can, sink everything you can.

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.

Re:GCC 7 Release Series – Changes, New Features, and Fixes by mindleyhilner on Sunday April 09, 2017 @01:09PM (#14073239)
The point of hoisting towards entry is to reduce code size, as the changelog indicates. It's safe to hoist the expression from program points P_{0..i..n-1} to some point Q that dominates all P_i if the expression is available at each P_i. That reduces the number of occurrences by n - 1. It's a basic corollary of PRE.

This is identical to what LLVM's load-store motion does for loads, except for all expressions and not just loads.

Re:GCC 7 Release Series – Changes, New Features, and Fixes by DannyBee on Sunday April 09, 2017 @01:10PM (#14073245)

  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 :)

Re:GCC 7 Release Series – Changes, New Features, and Fixes by mindleyhilner on Sunday April 09, 2017 @01:14PM (#14073273)

  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... (:
Re:GCC 7 Release Series – Changes, New Features, and Fixes by DannyBee on Sunday April 09, 2017 @04:53PM (#14074303)
Writing "TODO: generalize to other regions" in a crazy N^3/N^4 approach to merging load/stores is like writing "TODO: solve prime number conjecture" in somebody's hand-rolled two's complement addition code.

Maybe it happens, but it ain't gonna happen with anything like this code :)