[all-commits] [llvm/llvm-project] 0075a8: [GVN] Support load PRE through select addresses (i...
Pengcheng Wang via All-commits
all-commits at lists.llvm.org
Thu Jun 25 23:07:12 PDT 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 0075a8fbcc9928ef5a04a30233b08f67219a4310
https://github.com/llvm/llvm-project/commit/0075a8fbcc9928ef5a04a30233b08f67219a4310
Author: Pengcheng Wang <wangpengcheng.pp at bytedance.com>
Date: 2026-06-26 (Fri, 26 Jun 2026)
Changed paths:
M llvm/include/llvm/Analysis/MemoryDependenceAnalysis.h
M llvm/include/llvm/Analysis/PHITransAddr.h
M llvm/include/llvm/Transforms/Scalar/GVN.h
M llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
M llvm/lib/Analysis/PHITransAddr.cpp
M llvm/lib/Transforms/Scalar/GVN.cpp
M llvm/test/Transforms/GVN/PRE/pre-load-through-select.ll
Log Message:
-----------
[GVN] Support load PRE through select addresses (incl. indexed selects) (#203863)
This resurrects and extends the approach from the reverted
[D142705](https://reviews.llvm.org/D142705) ("[GVN] Support address
translation through select instructions"), adapting it to the current
GVN dependency model so that GVN can eliminate a redundant load whose
address is a `select` hidden behind cast/GEP indexing (the classic
`std::min_element` / min-index idiom, e.g. `data[*it] < data[*smallest]`
or returning the index `minloc`).
### What it does
When PHI translation of a load address fails along an edge because the
incoming value resolves to a `select`, we now translate **both** sides
of
that select to obtain the "true" and "false" addresses. If both
addresses
have a dominating, non-clobbered value of the right type, the load is
rematerialized as a `select` of those two values, letting the
loop-carried value be threaded through a phi over the backedge —
matching
GCC's `tree-ssa-pre` behavior, which previously produced one fewer load
in
the inner loop.
### Implementation
- `PHITransAddr`: `translateSubExpr` can resolve a select on a given
condition to one side and propagate that through casts/GEPs; adds
`getSelectCondition`, a pair-returning `translateValue`, the
`SelectAddr`
helper, and the value-preserving zext/sext-of-trunc fold.
- `MemoryDependenceAnalysis`: adds `MemDepResult::Select`;
`NonLocalDepResult`
carries a `SelectAddr`; on phi-translation failure with a
select-dependent
address, both sides are translated and a select dependency is reported.
- `GVN`: adds `DepKind::Select` to `ReachingMemVal` and
`AnalyzeSelectAvailability`; `AvailableValue` stores the select
condition so
the value select can be materialized at the load location.
### Testing
- Updated/added GVN regression tests, including negative cases
(intervening
clobbering store) and the indvars-canonicalized trunc form.
- Ran the full GVN + MemoryDependenceAnalysis test suites and
MemDep-consuming
passes (MemCpyOpt/DSE/LICM) — all pass.
- Ran llvm-test-suite (incl. SPEC CPU 2017 rate) for RISC-V `rva23u64`
under
QEMU: 2968/2968 tests PASS, no regressions.
Fixes #58569
Fixes #178616
Assisted-by: TraeCli (AI assistant)
Co-authored-by: Sergey Kachkov <sergey.kachkov at syntacore.com>
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