[all-commits] [llvm/llvm-project] 9d7161: [GVN] Simple GVN-based hoisring of scalars

Momchil Velikov via All-commits all-commits at lists.llvm.org
Fri Jul 17 06:26:40 PDT 2026


  Branch: refs/heads/users/momchil-velikov/gvn-simple-gvn-hoist-scalars
  Home:   https://github.com/llvm/llvm-project
  Commit: 9d7161d7eb6d82fa4564428d0a0bbccd356d2a2d
      https://github.com/llvm/llvm-project/commit/9d7161d7eb6d82fa4564428d0a0bbccd356d2a2d
  Author: Momchil Velikov <momchil.velikov at arm.com>
  Date:   2026-07-15 (Wed, 15 Jul 2026)

  Changed paths:
    M clang/test/CodeGen/attr-counted-by-with-sanitizers.c
    M llvm/include/llvm/Transforms/Scalar/GVN.h
    M llvm/lib/Transforms/Scalar/GVN.cpp
    M llvm/test/CodeGen/AMDGPU/memcpy-crash-issue63986.ll
    M llvm/test/CodeGen/NVPTX/gvn-scalar-pre-reg-pressure.ll
    M llvm/test/Transforms/GVN/2012-05-22-PreCrash.ll
    M llvm/test/Transforms/GVN/PRE/load-pre-across-backedge.ll
    M llvm/test/Transforms/GVN/PRE/local-pre.ll
    M llvm/test/Transforms/GVN/PRE/no-scalar-pre.ll
    M llvm/test/Transforms/GVN/PRE/phi-translate.ll
    M llvm/test/Transforms/GVN/PRE/pre-basic-add.ll
    M llvm/test/Transforms/GVN/PRE/pre-load-through-select.ll
    M llvm/test/Transforms/GVN/PRE/pre-no-cost-phi.ll
    M llvm/test/Transforms/GVN/PRE/pre-poison-add.ll
    M llvm/test/Transforms/GVN/freeze.ll
    M llvm/test/Transforms/GVN/gc_relocate.ll
    M llvm/test/Transforms/GVN/simple-gvn-hoist-limits.ll
    M llvm/test/Transforms/GVN/simple-gvn-hoist-scalars.ll

  Log Message:
  -----------
  [GVN] Simple GVN-based hoisring of scalars

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

This patch is a update of https://reviews.llvm.org/D110817

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:

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)

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. Also
instructions which read/write memory are not considered for hoisting,
subject for a follow-up patch. The hoist barriers can itself be hoisted,
opening opportunities for other instructions. For each hoist candidate
pair, the immediately preceding hoist barriers from then- and
else-blocks are recorded as prerequisites for hoisting the pair.

Next we try hoist to hoist each candidate pair. We begin by trying to
hoist dependencies of the then-instruction, which would be its
immediately preceding hoist barrier and its operands. Each of these
dependencies must already be in a dominating block or is itself paired
with an instruction from the else-block. If we cannot hoist an
dependency 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 barriers/operands of the else-instruction. They all
must already be in a dominating block, either initially or as a result
of hoisting barriers/operands of the then-instruction. If any dependency
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.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list