Skip to content

[AMDGPU][GlobalISel] Enable vector reductions #131413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,12 @@ static std::initializer_list<LLT> AllS32Vectors = {
static std::initializer_list<LLT> AllS64Vectors = {V2S64, V3S64, V4S64, V5S64,
V6S64, V7S64, V8S64, V16S64};

static std::initializer_list<LLT> AllVectors{
V2S16, V4S16, V6S16, V8S16, V10S16, V12S16, V16S16, V2S128,
V4S128, V2S32, V3S32, V4S32, V5S32, V6S32, V7S32, V8S32,
V9S32, V10S32, V11S32, V12S32, V16S32, V32S32, V2S64, V3S64,
V4S64, V5S64, V6S64, V7S64, V8S64, V16S64};

// Checks whether a type is in the list of legal register types.
static bool isRegisterClassType(const GCNSubtarget &ST, LLT Ty) {
if (Ty.isPointerOrPointerVector())
Expand Down Expand Up @@ -2106,6 +2112,15 @@ AMDGPULegalizerInfo::AMDGPULegalizerInfo(const GCNSubtarget &ST_,

getActionDefinitionsBuilder(G_PREFETCH).alwaysLegal();

getActionDefinitionsBuilder(
{G_VECREDUCE_SMIN, G_VECREDUCE_SMAX, G_VECREDUCE_UMIN, G_VECREDUCE_UMAX,
G_VECREDUCE_ADD, G_VECREDUCE_MUL, G_VECREDUCE_FMUL, G_VECREDUCE_FMIN,
G_VECREDUCE_FMAX, G_VECREDUCE_FMINIMUM, G_VECREDUCE_FMAXIMUM,
G_VECREDUCE_OR, G_VECREDUCE_AND, G_VECREDUCE_XOR})
.legalFor(AllVectors)
.scalarize(1)
.lower();

getLegacyLegalizerInfo().computeTables();
verify(*ST.getInstrInfo());
}
Expand Down
3,761 changes: 3,761 additions & 0 deletions llvm/test/CodeGen/AMDGPU/vector-reduce-add.ll

Large diffs are not rendered by default.

3,725 changes: 3,725 additions & 0 deletions llvm/test/CodeGen/AMDGPU/vector-reduce-and.ll

Large diffs are not rendered by default.

1,802 changes: 1,802 additions & 0 deletions llvm/test/CodeGen/AMDGPU/vector-reduce-fadd.ll

Large diffs are not rendered by default.

3,197 changes: 3,197 additions & 0 deletions llvm/test/CodeGen/AMDGPU/vector-reduce-fmax.ll

Large diffs are not rendered by default.

2,448 changes: 2,448 additions & 0 deletions llvm/test/CodeGen/AMDGPU/vector-reduce-fmaximum.ll

Large diffs are not rendered by default.

3,196 changes: 3,196 additions & 0 deletions llvm/test/CodeGen/AMDGPU/vector-reduce-fmin.ll

Large diffs are not rendered by default.

2,664 changes: 2,664 additions & 0 deletions llvm/test/CodeGen/AMDGPU/vector-reduce-fminimum.ll

Large diffs are not rendered by default.

1,802 changes: 1,802 additions & 0 deletions llvm/test/CodeGen/AMDGPU/vector-reduce-fmul.ll

Large diffs are not rendered by default.

4,667 changes: 4,667 additions & 0 deletions llvm/test/CodeGen/AMDGPU/vector-reduce-mul.ll

Large diffs are not rendered by default.

3,536 changes: 3,536 additions & 0 deletions llvm/test/CodeGen/AMDGPU/vector-reduce-or.ll

Large diffs are not rendered by default.

4,895 changes: 4,895 additions & 0 deletions llvm/test/CodeGen/AMDGPU/vector-reduce-smax.ll

Large diffs are not rendered by default.

4,895 changes: 4,895 additions & 0 deletions llvm/test/CodeGen/AMDGPU/vector-reduce-smin.ll

Large diffs are not rendered by default.

4,816 changes: 4,816 additions & 0 deletions llvm/test/CodeGen/AMDGPU/vector-reduce-umax.ll

Large diffs are not rendered by default.

4,465 changes: 4,465 additions & 0 deletions llvm/test/CodeGen/AMDGPU/vector-reduce-umin.ll

Large diffs are not rendered by default.

3,622 changes: 3,622 additions & 0 deletions llvm/test/CodeGen/AMDGPU/vector-reduce-xor.ll

Large diffs are not rendered by default.