[all-commits] [llvm/llvm-project] 8a12ca: [GVN] Support load of pointer-select to value-sele...

Florian Hahn via All-commits all-commits at lists.llvm.org
Wed Feb 2 01:23:31 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 8a12cae862af3208609127aaf288ab5298d33d38
      https://github.com/llvm/llvm-project/commit/8a12cae862af3208609127aaf288ab5298d33d38
  Author: Florian Hahn <flo at fhahn.com>
  Date:   2022-02-02 (Wed, 02 Feb 2022)

  Changed paths:
    M llvm/lib/Transforms/Scalar/GVN.cpp
    M llvm/test/Transforms/GVN/PRE/pre-load-through-select.ll
    M llvm/test/Transforms/GVN/PRE/pre-loop-load-through-select.ll

  Log Message:
  -----------
  [GVN] Support load of pointer-select to value-select conversion.

This patch extends the available-value logic to detect loads
of pointer-selects that can be replaced by a value select.

For example, consider the code below:

  loop:
    %sel.phi = phi i32* [ %start, %ph ], [ %sel, %ph ]
    %l = load %ptr
    %l.sel = load %sel.phi
    %sel = select cond, %ptr, %sel.phi
    ...

  exit:
    %res = load %sel
    use(%res)

The load of the pointer phi can be replaced by a load of the start value
outside the loop and a new phi/select chain based on the loaded values,
as illustrated below

    %l.start = load %start
  loop:
    sel.phi.prom = phi i32 [ %l.start, %ph ], [ %sel.prom, %ph ]
    %l = load %ptr
    %sel.prom = select cond, %l, %sel.phi.prom
    ...
  exit:
    use(%sel.prom)

This is a first step towards alllowing vectorizing loops using common libc++
library functions, like std::min_element (https://clang.godbolt.org/z/6czGzzqbs)

    #include <vector>
    #include <algorithm>

    int foo(const std::vector<int> &V) {
        return *std::min_element(V.begin(), V.end());
    }

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D118143




More information about the All-commits mailing list