[all-commits] [llvm/llvm-project] cc6320: [SimplifyCFG] Common code sinking: fix application...

Roman Lebedev via All-commits all-commits at lists.llvm.org
Thu Apr 29 11:12:12 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: cc63203908daa3a844d09160375c191003ab970c
      https://github.com/llvm/llvm-project/commit/cc63203908daa3a844d09160375c191003ab970c
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2021-04-29 (Thu, 29 Apr 2021)

  Changed paths:
    M llvm/lib/Transforms/Utils/SimplifyCFG.cpp
    M llvm/test/Transforms/SimplifyCFG/X86/sink-common-code.ll

  Log Message:
  -----------
  [SimplifyCFG] Common code sinking: fix application of profitability check

The profitability check is: we don't want to create more than a single PHI
per instruction sunk. We need to create the PHI unless we'll sink
all of it's would-be incoming values.

But there is a caveat there.
This profitability check doesn't converge on the first iteration!
If we first decide that we want to sink 10 instructions,
but then determine that 5'th one is unprofitable to sink,
that may result in us not sinking some instructions that
resulted in determining that some other instruction
we've determined to be profitable to sink becoming unprofitable.

So we need to iterate until we converge, as in determine
that all leftover instructions are profitable to sink.

But, the direct approach of just re-iterating seems dumb,
because in the worst case we'd find that the last instruction
is unprofitable, which would result in revisiting instructions
many many times.

Instead, i think we can get away with just two passes - forward and backward.
However then it isn't obvious what is the most performant way to update
InstructionsToSink.




More information about the All-commits mailing list