[PATCH] D110817: [GVN] Simple GVN hoist - scalars

Momchil Velikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 30 05:53:12 PDT 2021


chill created this revision.
Herald added a subscriber: hiraditya.
chill requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

RFC/discussion: https://lists.llvm.org/pipermail/llvm-dev/2021-September/152665.html

This patch implements simple hoisting of instructions from two
single-predecessor blocks to their common predecessor, as a subroutine
in the GVN pass.

The patch pairs two instructions (A and B) with the same value number,
moves A to the predecessor block, replaces all uses of B with A, and
deletes B.

Outline of the algorithm follows:

First we scan the then-block to collect hoist candidates ("then-" and "else-"
prefixes are purely naming and have no connection to the condition in the
predecessor block)

Then we scan the else-block for hoist candidates, that match some already
selected instruction from the then-block.

During both scans, instructions, which are not guaranteed to transfer control to
the following instruction act as "hoist barriers" - after we encounter such an
instruction, we select for potential hoisting/merge only instructions, which are
safe to execute speculatively.

Next we try hoist to hoist each candidate pair. We begin by trying to hoist
operands of the then-instruction.  Every such operand must already be in a
dominating block or in itself paired with an instruction from the else-block. If
we cannot hoist an operand for whatever reason, the we stop trying to hoist the
pair.

Now that all the operands of the then-instruction are in a dominating block, we
**check** the operands of the else-instruction. They all must already be in a
dominating block, either initially or as a result of hoisting operands of the
then-instruction. If any of the operands is still in the else-block, we stop
trying to hoist the pair.

As a last step, we move the then-instruction to the predecessor block and delete
the else-instruction.


https://reviews.llvm.org/D110817

Files:
  llvm/include/llvm/Transforms/Scalar/GVN.h
  llvm/lib/Transforms/Scalar/GVN.cpp
  llvm/test/Transforms/GVN/PRE/local-pre.ll
  llvm/test/Transforms/GVN/PRE/phi-translate.ll
  llvm/test/Transforms/GVN/PRE/pre-basic-add.ll
  llvm/test/Transforms/GVN/PRE/pre-load.ll
  llvm/test/Transforms/GVN/PRE/pre-no-cost-phi.ll
  llvm/test/Transforms/GVN/PRE/pre-poison-add.ll
  llvm/test/Transforms/GVN/freeze.ll
  llvm/test/Transforms/GVN/gc_relocate.ll
  llvm/test/Transforms/GVN/simple-gvnhoist-scalars.ll
  llvm/test/Transforms/InstCombine/phi-equal-incoming-pointers.ll
  llvm/test/Transforms/PhaseOrdering/AArch64/hoisting-sinking-required-for-vectorization.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110817.376153.patch
Type: text/x-patch
Size: 25629 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210930/f8e0c789/attachment.bin>


More information about the llvm-commits mailing list